class RedisHash

Public Instance Methods

[](key) click to toggle source
# File lib/redis-struct.rb, line 33
def [](key)
        @database.get prefix(key)
end
[]=(key,value) click to toggle source
# File lib/redis-struct.rb, line 29
def []=(key,value)
        @database.set prefix(key), value
end
add_hash() click to toggle source
# File lib/redis-struct.rb, line 79
def add_hash
        @hash.each_pair do |key,value|
                self[key] = value
        end
end
config_database(database) click to toggle source
# File lib/redis-struct.rb, line 9
def config_database(database)
        @database = database
end
config_hash(hash) click to toggle source

def config_redis_struct(redis_struct)

@redis_struct = redis_struct

end

# File lib/redis-struct.rb, line 25
def config_hash(hash)
        @hash = hash
end
config_prefix(prefix) click to toggle source
# File lib/redis-struct.rb, line 13
def config_prefix(prefix)
        @prefix = prefix
end
config_suffix(suffix) click to toggle source
# File lib/redis-struct.rb, line 17
def config_suffix(suffix)
        @suffix = suffix
end
delete(key) click to toggle source
# File lib/redis-struct.rb, line 85
def delete(key)
        @database.del prefix(key)
end
dup() click to toggle source
# File lib/redis-struct.rb, line 51
def dup 
        self
end
each_key() { |unprefix(key)| ... } click to toggle source
# File lib/redis-struct.rb, line 37
def each_key(&block)
        keys = @database.keys prefix("*")
        keys.each do |key|
                yield unprefix(key)
        end
end
each_pair() { |unprefix(key), value| ... } click to toggle source
# File lib/redis-struct.rb, line 44
def each_pair # (&block) ## I don't think this works.
        each_key do |key|
                value = self[key]
                yield unprefix(key), value
        end
end
get_suffix() click to toggle source
# File lib/redis-struct.rb, line 67
def get_suffix
        @suffix || self.object_id
end
prefix(key) click to toggle source
# File lib/redis-struct.rb, line 63
def prefix(key)
        "#{@prefix}:#{get_suffix}:#{key}"
end
prefix_with_id(key) click to toggle source
# File lib/redis-struct.rb, line 75
def prefix_with_id(key)
        "#{@prefix}:#{self.object_id}:#{key}"
end
to_h() click to toggle source
# File lib/redis-struct.rb, line 55
def to_h
        hash = {}
        each_key do |key|
                hash[key] = self[key]
        end
        hash
end
unprefix(key) click to toggle source
# File lib/redis-struct.rb, line 71
def unprefix(key)
        key.sub /^#{@prefix}:#{get_suffix}:/, ''
end