lib/redis/hash_key.rb in redis-objects-1.2.1 vs lib/redis/hash_key.rb in redis-objects-1.3.0
- old
+ new
@@ -70,10 +70,11 @@
h = redis.hgetall(key) || {}
h.each{|k,v| h[k] = unmarshal(v, options[:marshal_keys][k]) }
h
end
alias_method :clone, :all
+ alias_method :value, :all
# Enumerate through all fields. Redis: HGETALL
def each(&block)
all.each(&block)
end
@@ -127,21 +128,25 @@
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)
+ get_fields = *fields.flatten
+ get_fields << nil if get_fields.empty?
+ res = redis.hmget(key, get_fields)
fields.each do |k|
hsh[k] = unmarshal(res.shift, options[:marshal_keys][k])
end
hsh
end
# Get values in bulk, takes an array of keys as arguments.
# Values are returned in a collection in the same order than their keys in *keys Redis: HMGET
def bulk_values(*keys)
- res = redis.hmget(key, *keys.flatten)
+ get_keys = *keys.flatten
+ get_keys << nil if get_keys.empty?
+ res = redis.hmget(key, get_keys)
keys.inject([]){|collection, k| collection << unmarshal(res.shift, options[:marshal_keys][k])}
end
# Increment value by integer at field. Redis: HINCRBY
def incrby(field, by=1)
@@ -175,8 +180,12 @@
end
# Decrement value by float at field. Redis: HINCRBYFLOAT
def decrbyfloat(field, by=1.0)
incrbyfloat(field, -by)
+ end
+
+ def as_json(*)
+ to_hash
end
end
end