class NaiveBayes::Backend::Redis::RedisHash
Public Class Methods
new(redis, hash_name)
click to toggle source
# File lib/nb/backend/redis.rb, line 7 def initialize(redis, hash_name) @redis = redis @hash_name = hash_name end
Public Instance Methods
[](key)
click to toggle source
# File lib/nb/backend/redis.rb, line 12 def [](key) value = @redis.hget @hash_name, key value.to_f end
[]=(key, value)
click to toggle source
# File lib/nb/backend/redis.rb, line 17 def []=(key, value) @redis.hset @hash_name, key, value end
decr(key)
click to toggle source
# File lib/nb/backend/redis.rb, line 25 def decr(key) @redis.hdecrby @hash_name, key, 1 end
incr(key)
click to toggle source
# File lib/nb/backend/redis.rb, line 21 def incr(key) @redis.hincrby @hash_name, key, 1 end
map() { |k, self.[](k)| ... }
click to toggle source
# File lib/nb/backend/redis.rb, line 33 def map out = [] if block_given? @redis.hkeys(@hash_name).each { |k| out << yield(k, self.[](k)) } else out = to_enum :map end out end
values()
click to toggle source
# File lib/nb/backend/redis.rb, line 29 def values @redis.hvals(@hash_name).map(&:to_f) end