Class: Verdict::Storage::LegacyRedisStorage
- Inherits:
-
Object
- Object
- Verdict::Storage::LegacyRedisStorage
- Defined in:
- lib/verdict/storage/legacy_redis_storage.rb
Instance Attribute Summary collapse
-
#key_prefix ⇒ Object
Returns the value of attribute key_prefix.
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
-
#initialize(redis = nil, options = {}) ⇒ LegacyRedisStorage
constructor
A new instance of LegacyRedisStorage.
- #remove_assignment(experiment, subject_identifier) ⇒ Object
- #retrieve_assignment(experiment, subject_identifier) ⇒ Object
- #retrieve_start_timestamp(experiment) ⇒ Object
- #store_assignment(assignment) ⇒ Object
- #store_start_timestamp(experiment, timestamp) ⇒ Object
Constructor Details
#initialize(redis = nil, options = {}) ⇒ LegacyRedisStorage
Returns a new instance of LegacyRedisStorage.
6 7 8 9 |
# File 'lib/verdict/storage/legacy_redis_storage.rb', line 6 def initialize(redis = nil, = {}) @redis = redis @key_prefix = [:key_prefix] || 'experiments/' end |
Instance Attribute Details
#key_prefix ⇒ Object
Returns the value of attribute key_prefix.
4 5 6 |
# File 'lib/verdict/storage/legacy_redis_storage.rb', line 4 def key_prefix @key_prefix end |
#redis ⇒ Object
Returns the value of attribute redis.
4 5 6 |
# File 'lib/verdict/storage/legacy_redis_storage.rb', line 4 def redis @redis end |
Instance Method Details
#remove_assignment(experiment, subject_identifier) ⇒ Object
31 32 33 34 35 |
# File 'lib/verdict/storage/legacy_redis_storage.rb', line 31 def remove_assignment(experiment, subject_identifier) redis.hdel(generate_experiment_key(experiment), subject_identifier) rescue ::Redis::BaseError => e raise Verdict::StorageError, "Redis error: #{e.}" end |
#retrieve_assignment(experiment, subject_identifier) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/verdict/storage/legacy_redis_storage.rb', line 11 def retrieve_assignment(experiment, subject_identifier) if value = redis.hget(generate_experiment_key(experiment), subject_identifier) hash = JSON.parse(value) experiment.subject_assignment( subject_identifier, experiment.group(hash['group']), DateTime.parse(hash['created_at']).to_time ) end rescue ::Redis::BaseError => e raise Verdict::StorageError, "Redis error: #{e.}" end |
#retrieve_start_timestamp(experiment) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/verdict/storage/legacy_redis_storage.rb', line 37 def (experiment) if started_at = redis.get((experiment)) DateTime.parse(started_at).to_time end rescue ::Redis::BaseError => e raise Verdict::StorageError, "Redis error: #{e.}" end |
#store_assignment(assignment) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/verdict/storage/legacy_redis_storage.rb', line 24 def store_assignment(assignment) hash = { group: assignment.handle, created_at: assignment.created_at } redis.hset(generate_experiment_key(assignment.experiment), assignment.subject_identifier, JSON.dump(hash)) rescue ::Redis::BaseError => e raise Verdict::StorageError, "Redis error: #{e.}" end |
#store_start_timestamp(experiment, timestamp) ⇒ Object
45 46 47 48 49 |
# File 'lib/verdict/storage/legacy_redis_storage.rb', line 45 def (experiment, ) redis.setnx((experiment), .to_s) rescue ::Redis::BaseError => e raise Verdict::StorageError, "Redis error: #{e.}" end |