extra.redis: Replace 'redis-assoc' with the more general 'redis' type (now in the redis vocab), add support for automatic authentification when calling 'with-redis'
parent
462b66a696
commit
7edcc65159
|
@ -1,41 +1,22 @@
|
||||||
! Copyright (C) 2009 Bruno Deferrari
|
! Copyright (C) 2009 Bruno Deferrari
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs io.encodings.8-bit io.sockets
|
USING: assocs kernel redis sequences ;
|
||||||
io.streams.duplex kernel redis sequences ;
|
|
||||||
IN: redis.assoc
|
IN: redis.assoc
|
||||||
|
|
||||||
TUPLE: redis-assoc host port encoding password ;
|
INSTANCE: redis assoc
|
||||||
|
|
||||||
CONSTANT: default-redis-port 6379
|
M: redis at* [ redis-get dup >boolean ] with-redis ;
|
||||||
|
|
||||||
: <redis-assoc> ( -- redis-assoc )
|
M: redis assoc-size [ redis-dbsize ] with-redis ;
|
||||||
redis-assoc new
|
|
||||||
"127.0.0.1" >>host
|
|
||||||
default-redis-port >>port
|
|
||||||
latin1 >>encoding ;
|
|
||||||
|
|
||||||
INSTANCE: redis-assoc assoc
|
M: redis >alist [ "*" redis-keys dup redis-mget zip ] with-redis ;
|
||||||
|
|
||||||
: with-redis-assoc ( redis-assoc quot -- )
|
M: redis set-at [ redis-set drop ] with-redis ;
|
||||||
[
|
|
||||||
[ host>> ] [ port>> ] [ encoding>> ] tri
|
|
||||||
[ <inet> ] dip <client> drop
|
|
||||||
] dip with-stream ; inline
|
|
||||||
|
|
||||||
M: redis-assoc at* [ redis-get dup >boolean ] with-redis-assoc ;
|
M: redis delete-at [ redis-del drop ] with-redis ;
|
||||||
|
|
||||||
M: redis-assoc assoc-size [ redis-dbsize ] with-redis-assoc ;
|
M: redis clear-assoc [ "*" redis-keys [ redis-del drop ] each ] with-redis ;
|
||||||
|
|
||||||
M: redis-assoc >alist
|
M: redis equal? assoc= ;
|
||||||
[ "*" redis-keys dup redis-mget zip ] with-redis-assoc ;
|
|
||||||
|
|
||||||
M: redis-assoc set-at [ redis-set drop ] with-redis-assoc ;
|
M: redis hashcode* assoc-hashcode ;
|
||||||
|
|
||||||
M: redis-assoc delete-at [ redis-del drop ] with-redis-assoc ;
|
|
||||||
|
|
||||||
M: redis-assoc clear-assoc
|
|
||||||
[ "*" redis-keys [ redis-del drop ] each ] with-redis-assoc ;
|
|
||||||
|
|
||||||
M: redis-assoc equal? assoc= ;
|
|
||||||
|
|
||||||
M: redis-assoc hashcode* assoc-hashcode ;
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
! Copyright (C) 2009 Bruno Deferrari
|
! Copyright (C) 2009 Bruno Deferrari
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: io redis.response-parser redis.command-writer splitting ;
|
USING: accessors io io.encodings.8-bit io.sockets
|
||||||
|
io.streams.duplex kernel redis.command-writer
|
||||||
|
redis.response-parser splitting ;
|
||||||
IN: redis
|
IN: redis
|
||||||
|
|
||||||
#! Connection
|
#! Connection
|
||||||
|
@ -72,3 +74,24 @@ IN: redis
|
||||||
#! Remote server control
|
#! Remote server control
|
||||||
: redis-info ( -- response ) info flush read-response ;
|
: redis-info ( -- response ) info flush read-response ;
|
||||||
: redis-monitor ( -- response ) monitor 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
|
||||||
|
|
Loading…
Reference in New Issue