]> git.saurik.com Git - redis.git/blobdiff - client-libraries/ruby_2/rubyredis.rb
minor fix for Solaris boxes
[redis.git] / client-libraries / ruby_2 / rubyredis.rb
index 85989d35f458c8eb80830abd1e09beeeaf11f079..ca73d817d91fca08ef4fc6bcb3a6b64feaf1e587 100644 (file)
@@ -6,17 +6,18 @@
 # method_missing instead.
 
 require 'socket'
+require 'set'
 
 begin
-  if (RUBY_VERSION >= '1.9')
-    require 'timeout'
-    RedisTimer = Timeout
-  else
-    require 'system_timer'
-    RedisTimer = SystemTimer
-  end
+    if (RUBY_VERSION >= '1.9')
+        require 'timeout'
+        RedisTimer = Timeout
+    else
+        require 'system_timer'
+        RedisTimer = SystemTimer
+    end
 rescue LoadError
-  RedisTimer = nil
+    RedisTimer = nil
 end
 
 class RedisClient
@@ -58,7 +59,6 @@ class RedisClient
         "delete" => "del",
         "randkey" => "randomkey",
         "list_length" => "llen",
-        "type?" => "type",
         "push_tail" => "rpush",
         "push_head" => "lpush",
         "pop_tail" => "rpop",
@@ -74,13 +74,15 @@ class RedisClient
         "set_member?" => "sismember",
         "set_members" => "smembers",
         "set_intersect" => "sinter",
+        "set_intersect_store" => "sinterstore",
         "set_inter_store" => "sinterstore",
         "set_union" => "sunion",
         "set_union_store" => "sunionstore",
         "set_diff" => "sdiff",
         "set_diff_store" => "sdiffstore",
         "set_move" => "smove",
-        "set_unless_exists" => "setnx"
+        "set_unless_exists" => "setnx",
+        "rename_unless_exists" => "renamenx"
     }
 
     def initialize(opts={})
@@ -108,11 +110,13 @@ class RedisClient
             begin
                 sock = TCPSocket.new(host, port, 0)
             rescue Timeout::Error
+                @sock = nil
                 raise Timeout::Error, "Timeout connecting to the server"
             end
         else
             sock = TCPSocket.new(host, port, 0)
         end
+        sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
 
         # If the timeout is set we set the low level socket options in order
         # to make sure a blocking read will return after the specified number
@@ -149,7 +153,7 @@ class RedisClient
         bulk = nil
         argv[0] = argv[0].to_s.downcase
         argv[0] = Aliases[argv[0]] if Aliases[argv[0]]
-        if BulkCommands[argv[0]]
+        if BulkCommands[argv[0]] and argv.length > 1
             bulk = argv[-1].to_s
             argv[-1] = bulk.length
         end
@@ -228,7 +232,7 @@ class RedisClient
             }
             res
         else
-            raise "Protocol error, got '#{rtype}' as initial reply bye"
+            raise "Protocol error, got '#{rtype}' as initial reply byte"
         end
     end
 end