Skip to content

@WheresAlice /redis.io
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A basic Redis client in Io.
//metadoc Redis Alice Kaerast 2011
/*metadoc Redis description
redis is an open source, advanced key-value store
<br />An example:
<pre>
myredis := Redis clone connect("127.0.0.1:6379")
myredis send("rpush", "foo", "bar")
</pre>
*/
Redis := Object clone do(
debug ::= true
connect := method(addr,
if(debug, writeln("connecting"))
host := addr split(":") first
port := addr split(":") second asNumber
self socket := Socket clone setHost(host) setPort(port) connect
if(debug, writeln("connected"))
self
)
disconnect := method(
socket close
self
)
send := method(
methodSize := call message arguments size
i := 0
sendString := ""
while(i < methodSize, sendString := sendString .. call evalArgAt(i) .. " "; i = i + 1)
command(sendString)
)
command := method(cmd,
cmd := cmd split
cmdstring := "*#{cmd size}\r\n" interpolate
i := 0
while(i < cmd size, cmdstring := cmdstring .. "$#{cmd at(i) size}\r\n#{cmd at(i)}\r\n" interpolate; i := i + 1)
cmdstring := cmdstring
socket streamWrite(cmdstring)
response := socket readUntilSeq("\r\n") split
response
)
)
myredis := Redis clone connect("127.0.0.1:6379")
myredis send("rpush", "foo", "bar") println
myredis send("exists", "foo") println
myredis send("exists", "bar") println
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.