lib/redis.rb in redis-2.0.2 vs lib/redis.rb in redis-2.0.3

- old
+ new

@@ -1,9 +1,9 @@ require 'socket' class Redis - VERSION = "2.0.2" + VERSION = "2.0.3" class ProtocolError < RuntimeError def initialize(reply_type) super("Protocol error, got '#{reply_type}' as initial reply byte") end @@ -34,31 +34,49 @@ else @client = Client.new(options) end end + def auth(password) + @client.call(:auth, password) + end + def select(db) @client.db = db @client.call(:select, db) end def info Hash[*@client.call(:info).split(/:|\r\n/)] end + def config(action, *args) + response = @client.call(:config, action, *args) + response = Hash[*response] if action == :get + response + end + def flushdb @client.call(:flushdb) end + def flushall + @client.call(:flushall) + end + def save @client.call(:save) end def bgsave @client.call(:bgsave) end + def bgrewriteaof + @client.call(:bgrewriteaof) + end + def get(key) @client.call(:get, key) end def getset(key, value) @@ -350,10 +368,18 @@ def mapped_hmset(key, hash) hmset(key, *hash.to_a.flatten) end + def hmget(key, *fields) + @client.call(:hmget, key, *fields) + end + + def mapped_hmget(key, *fields) + Hash[*fields.zip(hmget(key, *fields)).flatten] + end + def hlen(key) @client.call(:hlen, key) end def hvals(key) @@ -407,16 +433,11 @@ def mapped_msetnx(hash) msetnx(*hash.to_a.flatten) end def mapped_mget(*keys) - result = {} - mget(*keys).each do |value| - key = keys.shift - result.merge!(key => value) unless value.nil? - end - result + Hash[*keys.zip(mget(*keys)).flatten] end def sort(key, options = {}) command = CommandOptions.new(options) do |c| c.value :by @@ -452,9 +473,17 @@ def quit @client.call(:quit) rescue Errno::ECONNRESET ensure @client.disconnect + end + + def shutdown + @client.call(:shutdown) + end + + def slaveof(host, port) + @client.call(:slaveof, host, port) end def pipelined original, @client = @client, Pipeline.new yield