Merge branch 'redis' of git://www.tiodante.com/git/factor

db4
Slava Pestov 2009-05-13 16:59:12 -05:00
commit 9b79f9be4e
4 changed files with 49 additions and 2 deletions

View File

@ -0,0 +1,22 @@
! Copyright (C) 2009 Bruno Deferrari
! See http://factorcode.org/license.txt for BSD license.
USING: assocs kernel redis sequences ;
IN: redis.assoc
INSTANCE: redis assoc
M: redis at* [ redis-get dup >boolean ] with-redis ;
M: redis assoc-size [ redis-dbsize ] with-redis ;
M: redis >alist [ "*" redis-keys dup redis-mget zip ] with-redis ;
M: redis set-at [ redis-set drop ] with-redis ;
M: redis delete-at [ redis-del drop ] with-redis ;
M: redis clear-assoc [ redis-flushdb drop ] with-redis ;
M: redis equal? assoc= ;
M: redis hashcode* assoc-hashcode ;

View File

@ -0,0 +1 @@
Bruno Deferrari

View File

@ -0,0 +1 @@
Assoc protocol implementation for Redis

View File

@ -1,6 +1,8 @@
! Copyright (C) 2009 Bruno Deferrari
! See http://factorcode.org/license.txt for BSD license.
USING: io redis.response-parser redis.command-writer ;
USING: accessors io io.encodings.8-bit io.sockets
io.streams.duplex kernel redis.command-writer
redis.response-parser splitting ;
IN: redis
#! Connection
@ -23,7 +25,7 @@ IN: redis
: redis-type ( key -- response ) type flush read-response ;
#! Key space
: redis-keys ( pattern -- response ) keys flush read-response ;
: redis-keys ( pattern -- response ) keys flush read-response " " split ;
: redis-randomkey ( -- response ) randomkey flush read-response ;
: redis-rename ( newkey key -- response ) rename flush read-response ;
: redis-renamenx ( newkey key -- response ) renamenx flush read-response ;
@ -72,3 +74,24 @@ IN: redis
#! Remote server control
: redis-info ( -- response ) info flush read-response ;
: redis-monitor ( -- response ) monitor flush read-response ;
#! Redis object
TUPLE: redis host port encoding password ;
CONSTANT: default-redis-port 6379
: <redis> ( -- redis )
redis new
"127.0.0.1" >>host
default-redis-port >>port
latin1 >>encoding ;
: redis-do-connect ( redis -- stream )
[ host>> ] [ port>> ] [ encoding>> ] tri
[ <inet> ] dip <client> drop ;
: with-redis ( redis quot -- )
[
[ redis-do-connect ] [ password>> ] bi
[ swap [ [ redis-auth drop ] with-stream* ] keep ] when*
] dip with-stream ; inline