lib/redis/hash.rb in redis-objects-0.4.0 vs lib/redis/hash.rb in redis-objects-0.4.1
- old
+ new
@@ -9,11 +9,11 @@
include Redis::Helpers::CoreCommands
require 'redis/helpers/serialize'
include Redis::Helpers::Serialize
attr_reader :key, :redis
-
+
# Needed since Redis::Hash masks bare Hash in redis.rb
def self.[](*args)
::Hash[*args]
end
@@ -69,11 +69,11 @@
# Enumerate through all fields. Redis: HGETALL
def each(&block)
all.each(&block)
end
-
+
# Enumerate through each keys. Redis: HKEYS
def each_key(&block)
keys.each(&block)
end
@@ -100,27 +100,27 @@
end
# Set keys in bulk, takes a hash of field/values {'field1' => 'val1'}. Redis: HMSET
def bulk_set(*args)
raise ArgumentError, "Argument to bulk_set must be hash of key/value pairs" unless args.last.is_a?(::Hash)
- redis.hmset(key, *args.last.flatten)
+ redis.hmset(key, *args.last.inject([]){ |arr,kv| arr + kv })
end
-
+
# Get keys in bulk, takes an array of fields as arguments. Redis: HMGET
def bulk_get(*fields)
hsh = {}
res = redis.hmget(key, *fields.flatten)
fields.each do |k|
hsh[k] = res.shift
end
hsh
end
-
+
# Increment value by integer at field. Redis: HINCRBY
def incrby(field, val = 1)
redis.hincrby(key, field, val).to_i
end
- alias_method :incr, :incrby
+ alias_method :incr, :incrby
end
end