class Rudis::Hash
Public Instance Methods
all()
click to toggle source
# File lib/rudis/structures/hash.rb, line 50 def all redis.hgetall(key).map! do |k,v| [key_type.get(k), type.get(v)] end end
Also aliased as: to_h
default_options()
click to toggle source
# File lib/rudis/structures/hash.rb, line 3 def default_options { :type => DefaultType, :key_type => DefaultType } end
del(k)
click to toggle source
# File lib/rudis/structures/hash.rb, line 68 def del(k) redis.hdel(key, key_type.put(k)) end
empty?()
click to toggle source
# File lib/rudis/structures/hash.rb, line 64 def empty? len == 0 end
get(k)
click to toggle source
# File lib/rudis/structures/hash.rb, line 14 def get(k) e = redis.hget(key, key_type.put(k)) e && type.get(e) end
Also aliased as: []
has_key?(k)
click to toggle source
# File lib/rudis/structures/hash.rb, line 72 def has_key?(k) redis.hexists(key, key_type.put(k)) end
Also aliased as: include?
incr(k)
click to toggle source
# File lib/rudis/structures/hash.rb, line 81 def incr(k) incrby(k, 1) end
incrby(k, i)
click to toggle source
# File lib/rudis/structures/hash.rb, line 77 def incrby(k, i) redis.hincrby(key, key_type.put(k), i.to_i) end
key_type()
click to toggle source
# File lib/rudis/structures/hash.rb, line 10 def key_type @options[:key_type] end
keys()
click to toggle source
# File lib/rudis/structures/hash.rb, line 41 def keys redis.hkeys(key).map { |k| key_type.get(k) } end
len()
click to toggle source
# File lib/rudis/structures/hash.rb, line 57 def len redis.hlen(key) end
mget(*ks)
click to toggle source
# File lib/rudis/structures/hash.rb, line 25 def mget(*ks) ks.zip(redis.hmget(key, ks.map { |k| key_type.put(k) }).map { |v| type.get(v) }).to_h end
Also aliased as: slice
mset(hsh)
click to toggle source
# File lib/rudis/structures/hash.rb, line 34 def mset(hsh) hsh = hsh.dup hsh.map! {|k,v| [key_type.put(k), type.put(v)]} redis.hmset(key, *hsh.to_a.flatten) end
Also aliased as: merge!
set(k,v)
click to toggle source
# File lib/rudis/structures/hash.rb, line 20 def set(k,v) redis.hset(key, key_type.put(k), type.put(v)) end
Also aliased as: []=
vals()
click to toggle source
# File lib/rudis/structures/hash.rb, line 45 def vals redis.hvals(key).map { |v| type.get(v) } end
Also aliased as: values