Class: Moderation::Storage::Redis
- Inherits:
-
Object
- Object
- Moderation::Storage::Redis
- Defined in:
- lib/moderation/storage/redis.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Redis
constructor
A new instance of Redis.
- #insert(item) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Redis
Returns a new instance of Redis.
9 10 11 12 13 |
# File 'lib/moderation/storage/redis.rb', line 9 def initialize( = {}) @limit = .fetch(:limit, Moderation::DEFAULT_LIMIT) @collection = .fetch(:collection) @server = .fetch(:server, nil) end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
6 7 8 |
# File 'lib/moderation/storage/redis.rb', line 6 def collection @collection end |
#limit ⇒ Object
Returns the value of attribute limit.
7 8 9 |
# File 'lib/moderation/storage/redis.rb', line 7 def limit @limit end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
6 7 8 |
# File 'lib/moderation/storage/redis.rb', line 6 def server @server end |
Instance Method Details
#all(options = {}) ⇒ Object
22 23 24 25 |
# File 'lib/moderation/storage/redis.rb', line 22 def all( = {}) fetch_limit = .fetch(:limit, limit).to_i - 1 redis.lrange(collection, 0, fetch_limit) || [] end |
#insert(item) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/moderation/storage/redis.rb', line 15 def insert(item) transaction do redis.lpush(collection, item) redis.ltrim(collection, 0, (limit - 1)) end end |