# 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
}
ConvertToBool = lambda{|r| r == 0 ? false : r}
+ ConvertToSet = lambda{|r| Set.new(r)}
ReplyProcessor = {
"exists" => ConvertToBool,
"del"=> ConvertToBool,
"renamenx"=> ConvertToBool,
"expire"=> ConvertToBool,
+ "smembers" => ConvertToSet,
+ "sinter" => ConvertToSet,
+ "sunion" => ConvertToSet,
+ "sdiff" => ConvertToSet,
"keys" => lambda{|r| r.split(" ")},
"info" => lambda{|r|
info = {}
"delete" => "del",
"randkey" => "randomkey",
"list_length" => "llen",
- "type?" => "type",
"push_tail" => "rpush",
"push_head" => "lpush",
"pop_tail" => "rpop",
"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={})
begin
sock = TCPSocket.new(host, port, 0)
rescue Timeout::Error
+ @sock = nil
raise Timeout::Error, "Timeout connecting to the server"
end
else
}
res
else
- raise "Protocol error, got '#{rtype}' as initial reply bye"
+ raise "Protocol error, got '#{rtype}' as initial reply byte"
end
end
end