source: project/wiki/eggref/4/redis-client @ 26962

Last change on this file since 26962 was 26962, checked in by svnwiki, 9 years ago

Anonymous wiki edit for IP [174.109.172.164]: Mismatched parens

File size: 4.4 KB
Line 
1[[toc:]]
2
3== Redis Client
4
5Redis [[http://redis.io/]] is a service that provides different types of memory based data structures such as queues and hashes.
6
7=== Description
8
9This egg is an implementation of the Redis protocol and a collection of wrapper procedures for Redis server commands.
10
11=== Authors
12
13[[/users/carl|Carl]]
14
15=== Requirements
16
17This depends on the {{socket}} egg.
18
19To run the tests, you will need a local running Redis service.
20
21=== API
22
23<procedure>(redis-connect hostname port)</procedure>
24
25Connect to the Redis server.
26
27<parameter>(*redis-in-port*)</parameter>
28
29The 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.
30
31<parameter>(*redis-out-port*)</parameter>
32
33The 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.
34
35<procedure>(redis-read-response port)</procedure>
36
37Read 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.
38
39<procedure>(redis-write-command port command args)</procedure>
40
41Send a command to the redis service. Generally, instead use the command wrapper procedures.
42
43<procedure>(redis-publish channel-name message)</procedure>
44
45Publish a message on a channel.
46
47<procedure>(redis-ping)</procedure>
48
49Ping redis. An immediate pong response should be returned.
50
51
52For a full list of Redis commands, visit [[http://redis.io/commands]].
53
54=== Examples
55
56This 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"}}.
57
58  (use redis-client)
59  (pp (redis-connect "127.0.0.1" 6379))
60  (pp (redis-publish "HelloChannel" "Hello, World!"))
61
62The 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}}.
63
64  ; Usage:
65  ;   csi -s subscriber.scm my-channel-name
66  (use srfi-1 redis-client)
67  (redis-connect "127.0.0.1" 6379)
68  (redis-subscribe (last (command-line-arguments)))
69  (define (run-loop thunk)
70    (let ((response (redis-read-response (*redis-in-port*))))
71       (thunk response))
72    (run-loop thunk))
73  (run-loop
74    (lambda(r)
75      (printf "->~S~%" r)))
76
77Here's an example of using the LPUSH and RPOP commands.
78
79  (use redis-client)
80  (pp (redis-connect "127.0.0.1" 6379))
81  (pp (redis-lpush "test-queue" "Hello!"))
82  (pp (redis-rpop  "test-queue"))
83
84=== License
85
86Copyright (C) 2011, A. Carl Douglas
87All rights reserved.
88
89Redistribution and use in source and binary forms, with or without
90modification, are permitted provided that the following conditions are met:
91
92Redistributions of source code must retain the above copyright notice, this
93list of conditions and the following disclaimer.
94Redistributions in binary form must reproduce the above copyright notice,
95this list of conditions and the following disclaimer in the documentation
96and/or other materials provided with the distribution.
97Neither the name of the author nor the names of its contributors may be
98used to endorse or promote products derived from this software without
99specific prior written permission.
100
101THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
102AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
103IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
104ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
105LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
106CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
107SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
108INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
109CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
110ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
111POSSIBILITY OF SUCH DAMAGE.
112
113=== Repository
114
115[[https://github.com/carld/redis-client.egg]]
116
117=== Version History
118
119* 0.5  Don't raise errors when running tests from salmonella, added more tests, commands to upper case.
120* 0.4  Define redis procedures using a hygienic macro. Added redis-echo, redis-strlen.
121* 0.3  Initial publication.
Note: See TracBrowser for help on using the repository browser.