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 17 18 |
# File 'lib/hyrax/redis_event_store.rb', line 9 def create(action, ) instance.then do |redis| event_id = redis.incr("events:latest_id") redis.hmset("events:#{event_id}", "action", action, "timestamp", ) event_id end 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.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hyrax/redis_event_store.rb', line 27 def instance if Hyrax.config.redis_connection&.is_a?(Redis::Namespace) c = Hyrax.config.redis_connection c.namespace = namespace c elsif Hyrax.config.redis_connection Hyrax.config.redis_connection else Redis::Namespace.new(namespace, redis: Redis.new) end 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.
42 43 44 |
# File 'lib/hyrax/redis_event_store.rb', line 42 def namespace Hyrax.config.redis_namespace end |
Instance Method Details
#fetch(size) ⇒ Enumerable<Hash<Symbol, String>>
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hyrax/redis_event_store.rb', line 51 def fetch(size) Hyrax::RedisEventStore.instance.then do |redis| redis.lrange(@key, 0, size).map do |event_id| { action: redis.hget("events:#{event_id}", "action"), timestamp: redis.hget("events:#{event_id}", "timestamp") } end 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
71 72 73 74 75 76 |
# File 'lib/hyrax/redis_event_store.rb', line 71 def push(value) Hyrax::RedisEventStore.instance.then { |r| r.lpush(@key, value) } rescue Redis::CommandError, Redis::CannotConnectError RedisEventStore.logger.error("unable to push event: #{@key}") nil end |