]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/redis/command-writer/command-writer.factor
feature(redis): lua script words
[factor.git] / extra / redis / command-writer / command-writer.factor
index f407a125061584076a395509f941e161a035c012..6657f64b0a5bffab56afafe7de1874912ac44aa3 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Bruno Deferrari
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays assocs formatting io io.crlf kernel math
-math.parser sequences strings locals ;
+USING: arrays assocs formatting kernel math math.parser
+sequences strings make ;
 IN: redis.command-writer
 
 <PRIVATE
@@ -23,6 +23,16 @@ M: sequence write-resp ( sequence -- )
     [ dup number? [ number>string ] when ] map
     write-resp ;
 
+: write-command-multi ( sequence command -- )
+    prepend
+    [ dup number? [ number>string ] when ] map
+    write-resp ;
+
+:: (script-eval) ( script keys args command -- )
+    [ script , keys length , keys % args % ] { } make
+    { command }
+    write-command-multi ;
+
 PRIVATE>
 
 ! Connection
@@ -106,6 +116,7 @@ PRIVATE>
 ! Multiple db
 : select ( integer -- ) 1array "SELECT" write-command ;
 : move ( integer key -- ) 2array "MOVE" write-command ;
+: swapdb ( old new -- ) 2array "SWAPDB" write-command ;
 : flushdb ( -- ) { "FLUSHDB" } write-resp ;
 : flushall ( -- ) { "FLUSHALL" } write-resp ;
 
@@ -121,3 +132,13 @@ PRIVATE>
 ! Remote server control
 : info ( -- ) { "INFO" } write-resp ;
 : monitor ( -- ) { "MONITOR" } write-resp ;
+
+! Lua
+: script-load ( script -- ) 1array { "SCRIPT" "LOAD" } write-command-multi ;
+: script-exists ( scripts -- ) { "SCRIPT" "EXISTS" } write-command-multi ;
+: script-flush ( -- ) { } { "SCRIPT" "FLUSH" } write-command-multi ;
+: script-kill ( -- ) { } { "SCRIPT" "KILL" } write-command-multi ;
+! YES | SYNC | NO
+: script-debug ( debug -- ) 1array { "SCRIPT" "DEBUG" } write-command-multi ;
+: script-evalsha ( sha keys args -- ) "EVALSHA" (script-eval) ;
+: script-eval ( script keys args -- ) "EVAL" (script-eval) ;