lib/redis/hash_key.rb in redis-objects-1.1.0 vs lib/redis/hash_key.rb in redis-objects-1.2.0
- old
+ new
@@ -16,11 +16,13 @@
@options[:marshal_keys] ||= {}
end
# Redis: HSET
def store(field, value)
- redis.hset(key, field, marshal(value, options[:marshal_keys][field]))
+ allow_expiration do
+ redis.hset(key, field, marshal(value, options[:marshal_keys][field]))
+ end
end
alias_method :[]=, :store
# Redis: HGET
def hget(field)
@@ -35,12 +37,12 @@
end
alias_method :include?, :has_key?
alias_method :key?, :has_key?
alias_method :member?, :has_key?
- # Delete field. Redis: HDEL
- def delete(field)
+ # Delete fields. Redis: HDEL
+ def delete(*field)
redis.hdel(key, field)
end
# Fetch a key in a way similar to Ruby's Hash#fetch
def fetch(field, *args, &block)
@@ -104,21 +106,25 @@
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.inject([]){ |arr,kv|
- arr + [kv[0], marshal(kv[1], options[:marshal_keys][kv[0]])]
- })
+ allow_expiration do
+ redis.hmset(key, *args.last.inject([]){ |arr,kv|
+ arr + [kv[0], marshal(kv[1], options[:marshal_keys][kv[0]])]
+ })
+ end
end
alias_method :update, :bulk_set
# Set keys in bulk if they do not exist. Takes a hash of field/values {'field1' => 'val1'}. Redis: HSETNX
def fill(pairs={})
raise ArgumentError, "Arugment to fill must be a hash of key/value pairs" unless pairs.is_a?(::Hash)
- pairs.each do |field, value|
- redis.hsetnx(key, field, marshal(value, options[:marshal_keys][field]))
+ allow_expiration do
+ pairs.each do |field, value|
+ redis.hsetnx(key, field, marshal(value, options[:marshal_keys][field]))
+ end
end
end
# Get keys in bulk, takes an array of fields as arguments. Redis: HMGET
def bulk_get(*fields)
@@ -137,15 +143,17 @@
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)
- ret = redis.hincrby(key, field, by)
- unless ret.is_a? Array
- ret.to_i
- else
- nil
+ allow_expiration do
+ ret = redis.hincrby(key, field, by)
+ unless ret.is_a? Array
+ ret.to_i
+ else
+ nil
+ end
end
end
alias_method :incr, :incrby
# Decrement value by integer at field. Redis: HINCRBY
@@ -154,24 +162,21 @@
end
alias_method :decr, :decrby
# Increment value by float at field. Redis: HINCRBYFLOAT
def incrbyfloat(field, by=1.0)
- ret = redis.hincrbyfloat(key, field, by)
- unless ret.is_a? Array
- ret.to_f
- else
- nil
+ allow_expiration do
+ ret = redis.hincrbyfloat(key, field, by)
+ unless ret.is_a? Array
+ ret.to_f
+ else
+ nil
+ end
end
end
# Decrement value by float at field. Redis: HINCRBYFLOAT
def decrbyfloat(field, by=1.0)
incrbyfloat(field, -by)
end
-
- expiration_filter :[]=, :store, :bulk_set, :fill,
- :incrby, :incr, :incrbyfloat,
- :decrby, :decr, :decrbyfloat
end
end
-