Method: RedisStruct#initialize
- Defined in:
- lib/redis-struct.rb
#initialize(hash = nil, prefix = 'redis_struct', suffix = nil, database) ⇒ RedisStruct
An RedisStruct wraps the OpenStruct class, which uses method_missing to store values in a hash. Instead, RedisStruct stores these values in Redis, providing a pleasant way of interfacing with $redis.
#When $redis = Redis.new :host => ‘0.0.0.0’, :port => ‘6379’ example = RedisStruct.new($redis)
example.color = ‘blue’
example.color # => ‘blue’
The hash will load any data you want into the RedisStruct, without having to iterate over it. And the prefix is what’s used to store in $redis. Good luck!
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/redis-struct.rb', line 152 def initialize(hash=nil, prefix = 'redis_struct', suffix = nil, database) @table = RedisHash.new @table.config_database database @table.config_prefix prefix if suffix @table.config_suffix suffix end # Enables the user to load a hash into the database # Hash will be compiled later - once the RedisStruct's name is known @table.config_hash hash @table.add_hash if hash end |