]> 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 af6ac6021c50fc85944f5c0260bd9c6b2cba3fb3..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 kernel math math.parser
-sequences strings ;
+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
@@ -122,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) ;