src/newseasons/models/shows.clj @ 89f24149ecd7

Start a refresh loop.
author Steve Losh <steve@stevelosh.com>
date Mon, 03 Oct 2011 21:28:10 -0400
parents a77d48fb4f63
children 472b20cb4c5f
(ns newseasons.models.shows
  (:use newseasons.models.keys)
  (:use [aleph.redis :only (redis-client)]))


(def r (redis-client {:host "localhost" :password "devpass"}))

; "Schema" --------------------------------------------------------------------
;
; Shows are stored as hashes.
;
; shows:<iTunes artist ID> = {
;     id: show id
;     title: show tile
;     latest: description of the latest season
;     image: url to show's image
;     url: url to view the show on iTunes
; }
;
; The shows we need to check are stored in two places for durability and ease of
; use:
;
; shows:to-check = z#{<iTunes artist ID>, ...}
; shows:to-check:queue = [<iTunes artist ID, ...]
;              push to --^                      ^-- pop from

; Code ------------------------------------------------------------------------

(defn show-get [id]
  (let [show (apply hash-map @(r [:hgetall (key-show id)]))]
    (when (not (empty? show))
      {:id (show "id")
       :title (show "title")
       :image (show "image")
       :latest (show "latest")
       :url (show "url")})))

(defn show-set-id! [id new-id]
  @(r [:hset (key-show id) "id" new-id]))

(defn show-set-title! [id new-title]
  @(r [:hset (key-show id) "title" new-title]))

(defn show-set-latest! [id new-latest]
  @(r [:hset (key-show id) "latest" new-latest]))

(defn show-set-image! [id new-image]
  @(r [:hset (key-show id) "image" new-image]))

(defn show-set-url! [id new-url]
  @(r [:hset (key-show id) "url" new-url]))


(defn show-add-to-check! [id]
  @(r [:sadd "shows:to-check" id]))

(defn shows-get-to-check []
  @(r [:smembers "shows:to-check"]))