]>
git.saurik.com Git - redis.git/blob - client-libraries/ruby_2/rubyredis.rb
1 # RubyRedis is an alternative implementatin of Ruby client library written
2 # by Salvatore Sanfilippo.
4 # The aim of this library is to create an alternative client library that is
5 # much simpler and does not implement every command explicitly but uses
6 # method_missing instead.
12 "set"=>true, "setnx"=>true, "rpush"=>true, "lpush"=>true, "lset"=>true,
13 "lrem"=>true, "sadd"=>true, "srem"=>true, "sismember"=>true,
14 "echo"=>true, "getset"=>true, "smove"=>true
17 def initialize(opts
={})
18 opts
= {:host => 'localhost', :port => '6379', :db => 0}.merge(opts
)
22 @sock = connect_to_server
26 "Redis Client connected to #{@host}:#{@port} against DB #{@db}"
30 TCPSocket
.new(@host, @port, 0)
33 def method_missing(*argv)
37 def call_command(argv)
39 argv[0] = argv[0].to_s
.downcase
40 if BulkCommands
[argv[0]]
42 argv[-1] = bulk
.length
44 @sock.write(argv.join(" ")+
"\r\n")
45 @sock.write(bulk+
"\r\n") if bulk
59 bulklen = line[1..-1].to_i
60 return nil if bulklen == -1
61 data = @sock.read(bulklen)
65 objects = line[1..-1].to_i
66 return nil if bulklen == -1