]>
git.saurik.com Git - redis.git/blob - client-libraries/ruby_2/rubyredis.rb
117f2efa1591b5a93e0d23fbc20f3b53d39f582d
   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
 
  23         call_command(["select",@db]) if @db !
= 0 
  27         "Redis Client connected to #{@host}:#{@port} against DB #{@db}" 
  31         TCPSocket
.new(@host, @port, 0) 
  34     def method_missing(*argv) 
  38     def call_command(argv) 
  40         argv[0] = argv[0].to_s
.downcase
 
  41         if BulkCommands
[argv[0]] 
  43             argv[-1] = bulk
.length
 
  45         @sock.write(argv.join(" ")+
"\r\n") 
  46         @sock.write(bulk+
"\r\n") if bulk
 
  51         raise "SELECT not allowed, use the :db option when creating the object" 
  64             bulklen = line[1..-1].to_i 
  65             return nil if bulklen == -1 
  66             data = @sock.read(bulklen) 
  70             objects = line[1..-1].to_i 
  71             return nil if bulklen == -1 
  81 r = RedisClient.new(:db=>0)