Class: SplitIoClient::Cache::Repositories::Impressions::RedisRepository
- Inherits:
-
SplitIoClient::Cache::Repositories::ImpressionsRepository
- Object
- SplitIoClient::Cache::Repository
- SplitIoClient::Cache::Repositories::ImpressionsRepository
- SplitIoClient::Cache::Repositories::Impressions::RedisRepository
- Defined in:
- lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
Constant Summary collapse
- EXPIRE_SECONDS =
3600
Instance Method Summary collapse
- #add(matching_key, bucketing_key, split_name, treatment, time) ⇒ Object
- #add_bulk(matching_key, bucketing_key, treatments, time) ⇒ Object
- #batch ⇒ Object
-
#initialize(adapter) ⇒ RedisRepository
constructor
A new instance of RedisRepository.
- #key ⇒ Object
Methods inherited from SplitIoClient::Cache::Repository
Constructor Details
#initialize(adapter) ⇒ RedisRepository
Returns a new instance of RedisRepository.
10 11 12 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 10 def initialize(adapter) @adapter = adapter end |
Instance Method Details
#add(matching_key, bucketing_key, split_name, treatment, time) ⇒ Object
14 15 16 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 14 def add(matching_key, bucketing_key, split_name, treatment, time) add_bulk(matching_key, bucketing_key, { split_name => treatment }, time) end |
#add_bulk(matching_key, bucketing_key, treatments, time) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 18 def add_bulk(matching_key, bucketing_key, treatments, time) impressions = treatments.map do |split_name, treatment| { m: , i: impression_data( matching_key, bucketing_key, split_name, treatment, time ) }.to_json end impressions_list_size = @adapter.add_to_queue(key, impressions) # Synchronizer might not be running @adapter.expire(key, EXPIRE_SECONDS) if impressions.size == impressions_list_size end |
#batch ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 38 def batch @adapter.get_from_queue(key, SplitIoClient.configuration.impressions_bulk_size).map do |e| impression = JSON.parse(e, symbolize_names: true) impression[:i][:f] = impression[:i][:f].to_sym impression end rescue StandardError => e SplitIoClient.configuration.logger.error("Exception while clearing impressions cache: #{e}") [] end |
#key ⇒ Object
49 50 51 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 49 def key @key ||= namespace_key('.impressions') end |