]> git.saurik.com Git - redis.git/commitdiff
command postprocessing implemented into RubyRedis
authorantirez <antirez@gmail.com>
Thu, 21 May 2009 11:22:20 +0000 (13:22 +0200)
committerantirez <antirez@gmail.com>
Thu, 21 May 2009 11:22:20 +0000 (13:22 +0200)
TODO
client-libraries/ruby_2/rubyredis.rb
redis.c

diff --git a/TODO b/TODO
index e40a7ed444ca40eb9b16dfff3ae77d3d0fb9a2d6..02a5f57728ed2e9e258cda1417d278ac52b191fb 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,5 @@
 BEFORE REDIS 1.0.0-rc1
 
- * S*STORE should allow as dest key one of the source keys
  * Warning if using default config, with hint about 'redis-server redis.conf'
  * Add number of keys for every DB in INFO
  * maxmemory support
index 77b0e9d27e827db75f09bb5c178bc9294ad7a635..e4921a23becc1a067e72480d83f2419ee6c492b4 100644 (file)
@@ -14,6 +14,35 @@ class RedisClient
         "echo"=>true, "getset"=>true, "smove"=>true
     }
 
+    ConvertToBool = lambda{|r| r == 0 ? false : r}
+
+    ReplyProcessor = {
+        "exists" => ConvertToBool,
+        "sismember"=> ConvertToBool,
+        "sadd"=> ConvertToBool,
+        "srem"=> ConvertToBool,
+        "smove"=> ConvertToBool,
+        "move"=> ConvertToBool,
+        "setnx"=> ConvertToBool,
+        "del"=> ConvertToBool,
+        "renamenx"=> ConvertToBool,
+        "expire"=> ConvertToBool,
+        "keys" => lambda{|r| r.split(" ")},
+        "info" => lambda{|r| 
+            info = {}
+            r.each_line {|kv|
+                k,v = kv.split(':', 2)
+                k,v = k.chomp, v = v.chomp
+                info[k.to_sym] = v
+            }
+            info
+        }
+    }
+
+    def convert_to_bool(r)
+        r == 0 ? false : r
+    end
+
     def initialize(opts={})
         opts = {:host => 'localhost', :port => '6379', :db => 0}.merge(opts)
         @host = opts[:host]
@@ -52,12 +81,15 @@ class RedisClient
         bulk = nil
         argv[0] = argv[0].to_s.downcase
         if BulkCommands[argv[0]]
-            bulk = argv[-1]
+            bulk = argv[-1].to_s
             argv[-1] = bulk.length
         end
         @sock.write(argv.join(" ")+"\r\n")
         @sock.write(bulk+"\r\n") if bulk
-        read_reply
+
+        # Post process the reply if needed
+        processor = ReplyProcessor[argv[0]]
+        processor ? processor.call(read_reply) : read_reply
     end
 
     def select(*args)
diff --git a/redis.c b/redis.c
index fbd1bc3df1807678cc297dcdc8ec3958f4061c84..6adf521ba63f59860cf30d7d2f040f637223b44e 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -2973,7 +2973,7 @@ static void sinterGenericCommand(redisClient *c, robj **setskeys, int setsnum, r
     robj *lenobj = NULL, *dstset = NULL;
     int j, cardinality = 0;
 
-    if (!dv) oom("sinterCommand");
+    if (!dv) oom("sinterGenericCommand");
     for (j = 0; j < setsnum; j++) {
         robj *setobj;
 
@@ -3151,7 +3151,6 @@ static void sunionDiffGenericCommand(redisClient *c, robj **setskeys, int setsnu
         deleteKey(c->db,dstkey);
         dictAdd(c->db->dict,dstkey,dstset);
         incrRefCount(dstkey);
-        server.dirty++;
     }
 
     /* Cleanup */