Skip to content

Commit

Permalink
Initial commit. Fully working version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vseloved committed Nov 21, 2009
0 parents commit cc5072a
Show file tree
Hide file tree
Showing 8 changed files with 691 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
@@ -0,0 +1,7 @@
*~
*.fasl
\#*
.\#*
*.log
.*
!.gitignore
27 changes: 27 additions & 0 deletions LICENSE
@@ -0,0 +1,27 @@
Copyright (c) 2009 Vsevolod Dyomkin <vseloved@gmail.com>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

Except as contained in this notice, the name(s) of the above
copyright holders shall not be used in advertising or otherwise
to promote the sale, use or other dealings in this Software
without prior written authorization.

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
6 changes: 6 additions & 0 deletions README
@@ -0,0 +1,6 @@
CL-REDIS -- a Redis client for Common Lisp

Tested (not thoroughly) with version <1.1
Z-commands from 1.1 added, but not tested

TODO: extend and complete test-suite
41 changes: 41 additions & 0 deletions cl-redis.asd
@@ -0,0 +1,41 @@
;;; CL-REDIS system definition
;;; (c) Vsevolod Dyomkin, see LICENSE file for permissions

(in-package :asdf)

(defsystem #:cl-redis
:name "Redis client"
:version '(0 1 0)
:maintainer "Vsevolod Dyomkin <vseloved@gmail.com>"
:licence "MIT"
:description "A Redis database interface through socket"
:depends-on (:rutils :usocket :cl-ppcre)
:serial t
:components ((:file "package")
(:file "redis")
(:file "commands")))


#+:nuts
(defmethod perform ((o test-op)
(c (eql (find-system 'cl-redis))))
(operate 'load-op 'cl-redis)
(operate 'test-op 'cl-redis-test :force t))

#+:nuts
(defsystem #:cl-redis-test
:name "Redis client testsuite"
:version '(0 1 0)
:maintainer "Vsevolod Dyomkin <vseloved@gmail.com>"
:licence "MIT"
:description ""
:depends-on (:cl-redis :nuts)
:serial t
:components ((:file "test")))

(defmethod perform ((o test-op)
(c (eql (find-system 'cl-redis-test))))
(operate 'load-op '#:cl-redis-test)
(funcall (intern (symbol-name 'run-tests) '#:redis-test)))

;;; end
232 changes: 232 additions & 0 deletions commands.lisp
@@ -0,0 +1,232 @@
;;; CL-REDIS commands
;;; (c) Vsevolod Dyomkin, see LICENSE file for permissions


(in-package :redis)

(def-cmd PING "Ping server"
:inline () :pong)

(def-cmd QUIT "Close the connection"
:inline () :end)

(def-cmd AUTH "Simple password authentication if enabled"
:inline (pass) :ok)

(def-cmd SET "Set a key to a string value"
:bulk (key value) :ok)

(def-cmd GET "Return the string value of the key"
:inline (key) :bulk)

(def-cmd GETSET "Set a key to a string returning the old value of the key"
:bulk (key value) :bulk)

(def-cmd MGET "Multi-get, return the strings values of the keys"
:inline (&rest keys) :multi)

(def-cmd SETNX "Set a key to a string value if the key does not exist"
:bulk (key value) :boolean)

(def-cmd INCR "Increment the integer value of key"
:inline (key) :integer)

(def-cmd INCRBY "Increment the integer value of key by integer"
:inline (key integer) :integer)

(def-cmd DECR "Decrement the integer value of key"
:inline (key) :integer)

(def-cmd DECRBY "Decrement the integer value of key by integer"
:inline (key integer) :integer)

(def-cmd EXISTS "Test if a key exists"
:inline (key) :boolean)

(def-cmd DEL "Delete a key"
:inline (key) :boolean)

(def-cmd TYPE "Return the type of the value stored at key"
:inline (key) :inline)

(def-cmd KEYS "Return all the keys matching a given pattern"
:inline (pattern) :list)

(def-cmd RANDOMKEY "Return a random key from the key space"
:inline () :inline)

(def-cmd RENAME "Rename the old key in the new one, destroing the newname key ~
if it already exists"
:inline (oldname newname) :ok)

(def-cmd RENAMENX "Rename the old key in the new one, if the newname key ~
does not already exist"
:inline (oldname newname) :boolean)

(def-cmd DBSIZE "Return the number of keys in the current db"
:inline () :integer)

(def-cmd EXPIRE "Set a time to live in seconds on a key"
:inline (key secs) :boolean)

(def-cmd TTL "Get the time to live in seconds of a key"
:inline (key) :integer)


(def-cmd RPUSH "Append an element to the tail of the List value at key"
:bulk (key value) :ok)

(def-cmd LPUSH "Append an element to the head of the List value at key"
:bulk (key value) :ok)

(def-cmd LLEN "Return the length of the List value at key"
:inline (key) :integer)

(def-cmd LRANGE "Return a range of elements from the List at key"
:inline (key start end) :multi)

(def-cmd LTRIM "Trim the list at key to the specified range of elements"
:inline (key start end) :ok)

(def-cmd LINDEX "Return the element at index position from the List at key"
:inline (key index) :bulk)

(def-cmd LSET "Set a new value as the element at index position of the List ~
at key"
:bulk (key index value) :ok)

(def-cmd LREM "Remove the first-N, last-N, or all the elements matching value ~
from the List at key"
:bulk (key count value) :integer)

(def-cmd LPOP "Return and remove (atomically) the first element of the List~
at key"
:inline (key) :bulk)

(def-cmd RPOP "Return and remove (atomically) the last element of the List ~
at key"
:inline (key) :bulk)


(def-cmd SADD "Add the specified member to the Set value at key"
:bulk (key member) :boolean)

(def-cmd SREM "Remove the specified member from the Set value at key"
:bulk (key member) :boolean)

(def-cmd SPOP "Remove and return (pop) a random element from the Set value ~
at key"
:inline (key) :bulk)

(def-cmd SMOVE "Move the specified member from one Set to another atomically"
:bulk (srckey dstkey member) :boolean)

(def-cmd SCARD "Return the number of elements (the cardinality) of the Set ~
at key"
:inline (key) :integer)

(def-cmd SISMEMBER "Test if the specified value is a member of the Set at key"
:bulk (key member) :boolean)

(def-cmd SINTER "Return the intersection between the Sets stored ~
at key1, key2, ..., keyN"
:inline (&rest keys) :multi)

(def-cmd SINTERSTORE "Compute the intersection between the Sets stored ~
at key1, key2, ..., keyN, and store the resulting Set at dstkey"
:inline (dstkey &rest keys) :integer)

(def-cmd SUNION "Return the union between the Sets stored ~
at key1, key2, ..., keyN"
:inline (&rest keys) :multi)

(def-cmd SUNIONSTORE "Compute the union between the Sets stored ~
at key1, key2, ..., keyN, and store the resulting Set at dstkey"
:inline (dstkey &rest keys) :integer)

(def-cmd SDIFF "Return the difference between the Set stored ~
at key1 and all the Sets key2, ..., keyN"
:inline (&rest keys) :multi)

(def-cmd SDIFFSTORE "Compute the difference between the Set key1 and ~
all the Sets key2, ..., keyN, and store the resulting Set at dstkey"
:inline (dstkey &rest keys) :integer)

(def-cmd SMEMBERS "Return all the members of the Set value at key"
:inline (key) :multi)


(def-cmd ZADD "Add the specified member to the Set value at key or ~
update the score if it already exist.
If nil is returned, the element already existed in the set. Just the score ~
was updated"
:bulk (key score member) :boolean)

(def-cmd ZREM "Remove the specified member from the Set value at key"
:bulk (key member) :boolean)

(def-cmd ZRANGE "Return a range of elements from the sorted set at key"
:inline (key start end) :multi)

(def-cmd ZREVRANGE "Return a range of elements from the sorted set at key, ~
exactly like ZRANGE, but the sorted set is ordered in traversed in reverse ~
order, from the greatest to the smallest score"
:inline (key start end) :multi)

(def-cmd ZRANGEBYSCORE "Return all the elements with score >= min and ~
score <= max (a range query) from the sorted set"
:inine (key min max) :multi)

(def-cmd ZCARD "Return the cardinality (number of elements) of the sorted set ~
at key"
:inline (key) :integer)

(def-cmd ZSCORE "Return the score associated with the specified element of the ~
sorted set at key"
:bulk (key element) :string)


(def-cmd SELECT "Select the DB having the specified index"
:inline (index) :ok)

(def-cmd MOVE "Move the key from the currently selected DB to ~
the DB having as index dbindex"
:inline (key dbindex) :ok)

(def-cmd FLUSHDB "Remove all the keys of the currently selected DB"
:inline () :ok)

(def-cmd FLUSHALL "Remove all the keys from all the databases"
:inline () :ok)

(def-cmd SORT "Sort a Set or a List accordingly to the specified parameters"
:inline
(key &rest args &key BY #| pattern |# LIMIT #| start end |# GET #| pattern |#
ASC DESC ALPHA)
:ok)

(def-cmd SAVE "Synchronously save the DB on disk"
:inline () :ok)

(def-cmd BGSAVE "Asynchronously save the DB on disk"
:inline () :ok)

(def-cmd LASTSAVE "Return the UNIX time stamp of the last successfully ~
saving of the dataset on disk"
:inline () :integer)

(def-cmd SHUTDOWN "Synchronously save the DB on disk, then shutdown the server"
:inline () :end)

(def-cmd INFO "Provide information and statistics about the server"
:inline () :bulk)

#+nil
(def-cmd MONITOR "Dump all the received requests in real time"
:inline () :ok)

#+nil
(def-cmd SLAVEOF "Change the replication settings"
:inline (master) :ok)

;;; end
24 changes: 24 additions & 0 deletions package.lisp
@@ -0,0 +1,24 @@
;;; CL-REDIS package definition
;;; (c) Vsevolod Dyomkin, see LICENSE file for permissions

(in-package :cl-user)

(defpackage :redis
(:use :common-lisp :rutils.user :rutils.short :usocket
#+:nuts :nuts)
(:export #:*redis-in*
#:*redis-host*
#:*redis-out*
#:*redis-port*

#:*cmd-prefix*

#:def-cmd
#:def-expect-method
#:expect
#:redis-connect
#:tell

#:redis-error))

;;; end

0 comments on commit cc5072a

Please sign in to comment.