Class: Hyrax::RedisEventStore
- Inherits:
-
EventStore
- Object
- EventStore
- Hyrax::RedisEventStore
- Defined in:
- lib/hyrax/redis_event_store.rb
Class Method Summary collapse
-
.create(action, timestamp) ⇒ Fixnum?
The id of the event, or ‘nil` on failure(?!).
- .instance ⇒ Redis private
- .namespace ⇒ String private
Instance Method Summary collapse
- #fetch(size) ⇒ Enumerable<Hash<Symbol, String>>
-
#push(value) ⇒ Integer?
Adds a value to the end of a list identified by key.
Methods inherited from EventStore
Constructor Details
This class inherits a constructor from Hyrax::EventStore
Class Method Details
.create(action, timestamp) ⇒ Fixnum?
Returns the id of the event, or ‘nil` on failure(?!).
9 10 11 12 13 14 15 16 |
# File 'lib/hyrax/redis_event_store.rb', line 9 def create(action, ) event_id = instance.incr("events:latest_id") instance.hmset("events:#{event_id}", "action", action, "timestamp", ) event_id rescue Redis::CommandError => e logger.error("unable to create event: #{e}") nil end |
.instance ⇒ Redis
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Note:
this is NOT a singleton-ilke ‘.instance` method, it returns a `Redis` client.
25 26 27 28 29 30 31 32 |
# File 'lib/hyrax/redis_event_store.rb', line 25 def instance if Redis.current.is_a? Redis::Namespace Redis.current.namespace = namespace else Redis.current = Redis::Namespace.new(namespace, redis: Redis.current) end Redis.current end |
.namespace ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 |
# File 'lib/hyrax/redis_event_store.rb', line 37 def namespace Hyrax.config.redis_namespace end |
Instance Method Details
#fetch(size) ⇒ Enumerable<Hash<Symbol, String>>
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hyrax/redis_event_store.rb', line 46 def fetch(size) RedisEventStore.instance.lrange(@key, 0, size).map do |event_id| { action: RedisEventStore.instance.hget("events:#{event_id}", "action"), timestamp: RedisEventStore.instance.hget("events:#{event_id}", "timestamp") } end rescue Redis::CommandError, Redis::CannotConnectError RedisEventStore.logger.error("unable to fetch event: #{@key}") [] end |
#push(value) ⇒ Integer?
Adds a value to the end of a list identified by key
64 65 66 67 68 69 |
# File 'lib/hyrax/redis_event_store.rb', line 64 def push(value) RedisEventStore.instance.lpush(@key, value) rescue Redis::CommandError, Redis::CannotConnectError RedisEventStore.logger.error("unable to push event: #{@key}") nil end |