1 ;(add-classpath "file:///Users/ragge/Projects/clojure/redis-clojure/src/")
3 (set! *warn-on-reflection* true)
6 (:refer-clojure :exclude [get set type keys sort])
10 "Evaluates body in the context of a new connection to a Redis server
11 then closes the connection.
13 server-spec is a map with any of the following keys:
14 :host hostname (default \"127.0.0.1\")
15 :port port (default 6379)
16 :db database to use (default 0)"
18 `(with-server* ~server-spec (fn []
20 (redis/select (:db *server*))
25 ;; Reply conversion functions
28 "Convert integer reply to a boolean value"
32 (defn string-to-keyword
33 "Convert a string reply to a keyword"
38 "Convert a space separated string to a sequence of words"
42 (re-seq #"\S+" string)))
45 "Convert strings with format 'key:value\r\n'+ to a map with {key
48 (let [lines (.split string "(\\r\\n|:)")]
49 (apply hash-map lines)))
52 "Return a Date representation of a UNIX timestamp"
54 (new java.util.Date (long int)))
58 (clojure.core/set sequence))
64 ;; Connection handling
66 (quit [password] :inline)
69 (set [key value] :bulk)
71 (getset [key value] :bulk)
72 (setnx [key value] :bulk int-to-bool)
74 (incrby [key integer] :inline)
76 (decrby [key integer] :inline)
77 (exists [key] :inline int-to-bool)
78 (mget [key & keys] :inline)
79 (del [key] :inline int-to-bool)
81 (type [key] :inline string-to-keyword)
82 (keys [pattern] :inline string-to-seq)
83 (randomkey [] :inline)
84 (rename [oldkey newkey] :inline)
85 (renamenx [oldkey newkey] :inline int-to-bool)
87 (expire [key seconds] :inline int-to-bool)
90 (rpush [key value] :bulk)
91 (lpush [key value] :bulk)
93 (lrange [key start end] :inline)
94 (ltrim [key start end] :inline)
95 (lindex [key index] :inline)
96 (lset [key index value] :bulk)
97 (lrem [key count value] :bulk)
101 (sadd [key member] :bulk int-to-bool)
102 (srem [key member] :bulk int-to-bool)
103 (smove [srckey destkey member] :bulk int-to-bool)
104 (scard [key] :inline)
105 (sismember [key member] :bulk int-to-bool)
106 (sinter [key & keys] :inline seq-to-set)
107 (sinterstore [destkey key & keys] :inline)
108 (sunion [key & keys] :inline seq-to-set)
109 (sunionstore [destkey key & keys] :inline)
110 (sdiff [key & keys] :inline seq-to-set)
111 (sdiffstore [destkey key & keys] :inline)
112 (smembers [key] :inline seq-to-set)
113 ;; Multiple database handling commands
114 (select [index] :inline)
115 (move [key dbindex] :inline)
117 (flushall [] :inline)
119 (sort [key & options] :sort)
123 (lastsave [] :inline int-to-date)
124 (shutdown [] :inline)
125 (info [] :inline string-to-map)
126 ;;(monitor [] :inline))