Skip to content
manzyuk edited this page Sep 13, 2010 · 17 revisions

cl-redis

A fast and robust Common Lisp client for Redis database

dependencies

usage

  1. start Redis server
  2. (require 'cl-redis)
  3. (optinally) (setf redis:*redis-port* <actual-port>)
  4. (redis:redis-connect)
  5. (redis:red-ping) => “PONG
  6. (redis:redis-disconnect)

extending

There are 2 generic functions: tell and expect which implement different styles of Redis interactions according to the protocol. Tell specifies how a request to Redis is formatted and expect — how the response is handled. The best way to implement another method on expect is usually with def-expect-method, which arranges reading of data from the socket and provides a variable _raw, which holds the read string. For example:

(def-expect-method :ok
  (assert (string= _raw "OK"))
  _raw)

Redis operations are defined as functions with def-cmd for which only types of interactions and arguments should be provided. Def-cmd prefixes all the defined functions’ names with *cmd-prefix*, which defaults to 'red. (Note, that setting of *cmd-prefix* will have its effects at compile time). An example of command definition is below:

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

(see commands.lisp for all defined commands)

debugging, testing and error recovery

If *debug* is set to t, all input and output will be echoed to *standard-output*.

Clone this wiki locally