This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.
If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.
Redis http://redis.io/ is a service that provides different types of memory based data structures such as queues and hashes.
This egg is an implementation of the Redis protocol and a collection of wrapper procedures for Redis server commands.
This depends on the socket egg.
To run the tests, you will need a local running Redis service.
- redis-connect hostname portprocedure
Connect to the Redis server.
The above parameter is an input port for the socket that is connected to the redis service. This parameter is set by the redis-connect procedure.
The above parameter is an output port for the socket that is connect to the redis service. This parameter is set by the redis-connect procedure.
- redis-read-response portprocedure
Read a response from the redis service and return it as a list. This is useful when a command response from redis may not be immediate, for example the BRPOP or the SUBSCRIBE command.
- redis-write-command port command argsprocedure
Send a command to the redis service. Generally, instead use the command wrapper procedures.
- redis-publish channel-name messageprocedure
Publish a message on a channel.
Ping redis. An immediate pong response should be returned.
For a full list of Redis commands, visit http://redis.io/commands.
This simple example "Hello, World!" example will connect to a local Redis server and publish a message on a channel. Before running it, subscribe to the channel using the Redis command line interface tool, redis-cli subscribe "HelloChannel".
(use redis-client) (pp (redis-connect "127.0.0.1" 6379)) (pp (redis-publish "HelloChannel" "Hello, World!"))
The example below, demonstrates implementing your own message subscriber. It could be used to receive the "Hello, World" message published above, e.g. csi -s subscriber.scm HelloChannel.
; Usage: ; csi -s subscriber.scm my-channel-name (use srfi-1 redis-client) (redis-connect "127.0.0.1" 6379) (redis-subscribe (last (command-line-arguments))) (define (run-loop thunk) (let ((response (redis-read-response (*redis-in-port*)))) (thunk response)) (run-loop thunk)) (run-loop (lambda(r) (printf "->~S~%" r)))
Here's an example of using the LPUSH and RPOP commands.
(use redis-client) (pp (redis-connect "127.0.0.1" 6379)) (pp (redis-lpush "test-queue" "Hello!")) (pp (redis-rpop "test-queue"))
Copyright (C) 2011, A. Carl Douglas All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- 0.8 Fix protocol bug in redis-read-response. Introduce redis-transaction procedure.
- 0.7 Handle nil (-1) responses.
- 0.6 Refactor to use letret. Return all arguments in multi-bulk response.
- 0.5 Don't raise errors when running tests from salmonella, added more tests, commands to upper case.
- 0.4 Define redis procedures using a hygienic macro. Added redis-echo, redis-strlen.
- 0.3 Initial publication.