]> gitweb.factorcode.org Git - factor.git/commitdiff
extra.redis: Replace 'redis-assoc' with the more general 'redis' type (now in the...
authorBruno Deferrari <utizoc@gmail.com>
Mon, 11 May 2009 03:44:09 +0000 (00:44 -0300)
committerBruno Deferrari <utizoc@gmail.com>
Mon, 11 May 2009 03:44:09 +0000 (00:44 -0300)
extra/redis/assoc/assoc.factor
extra/redis/redis.factor

index 2ddf746344ecda712b05da314d2a6653670c0139..2830e93b25cc7212d9cdf83d5d6f3384c36c669d 100644 (file)
@@ -1,41 +1,22 @@
 ! Copyright (C) 2009 Bruno Deferrari
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs io.encodings.8-bit io.sockets
-io.streams.duplex kernel redis sequences ;
+USING: assocs kernel redis sequences ;
 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 )
-    redis-assoc new
-        "127.0.0.1" >>host
-        default-redis-port >>port
-        latin1 >>encoding ;
+M: redis assoc-size [ redis-dbsize ] with-redis ;
 
-INSTANCE: redis-assoc assoc
+M: redis >alist [ "*" redis-keys dup redis-mget zip ] with-redis ;
 
-: with-redis-assoc ( redis-assoc quot -- )
-    [
-        [ host>> ] [ port>> ] [ encoding>> ] tri
-        [ <inet> ] dip <client> drop
-    ] dip with-stream ; inline
+M: redis set-at [ redis-set drop ] with-redis ;
 
-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
-    [ "*" redis-keys dup redis-mget zip ] with-redis-assoc ;
+M: redis equal? assoc= ;
 
-M: redis-assoc set-at [ redis-set drop ] with-redis-assoc ;
-
-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 ;
+M: redis hashcode* assoc-hashcode ;
index a5e7d74d46f12720f90a2086b5e0cc959e6a864d..466fdc9937ae709f2ee2f7f3992ac40e86a0a8bb 100644 (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 splitting ;
+USING: accessors io io.encodings.8-bit io.sockets
+io.streams.duplex kernel redis.command-writer
+redis.response-parser splitting ;
 IN: redis
 
 #! Connection
@@ -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