Class: Blendris::RedisList
- Inherits:
-
Object
- Object
- Blendris::RedisList
- Includes:
- RedisNode, Enumerable
- Defined in:
- lib/blendris/list.rb
Overview
RedisList is a wrapper for the Redis LIST data type.
Instance Attribute Summary
Attributes included from RedisNode
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #delete(value) ⇒ Object
- #each ⇒ Object
- #get ⇒ Object
-
#initialize(key, options = {}) ⇒ RedisList
constructor
A new instance of RedisList.
Methods included from RedisNode
#clear, #exists?, #notify_changed, #rename, #set, #type
Methods included from RedisAccessor
database=, flushdb, #generate_key, #in_temporary_set, redis, #redis
Methods included from Utils
#blank, #camelize, #constantize, #sanitize_key
Constructor Details
#initialize(key, options = {}) ⇒ RedisList
Returns a new instance of RedisList.
10 11 12 13 14 |
# File 'lib/blendris/list.rb', line 10 def initialize(key, = {}) @key = key.to_s @options = @on_change = [:on_change] end |
Instance Method Details
#<<(value) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/blendris/list.rb', line 22 def <<(value) values = [ value ].flatten.compact values.flatten.compact.each do |v| redis.rpush key, v end notify_changed if values.count > 0 self end |
#delete(value) ⇒ Object
38 39 40 41 42 |
# File 'lib/blendris/list.rb', line 38 def delete(value) redis.lrem key, 0, value ensure notify_changed end |
#each ⇒ Object
16 17 18 19 20 |
# File 'lib/blendris/list.rb', line 16 def each redis.lrange(key, 0, -1).each do |value| yield value end end |
#get ⇒ Object
34 35 36 |
# File 'lib/blendris/list.rb', line 34 def get self end |