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
- #clear ⇒ Object
- #get_impressions(number_of_impressions = 0) ⇒ Object
-
#initialize(config) ⇒ RedisRepository
constructor
A new instance of RedisRepository.
- #key ⇒ Object
Methods inherited from SplitIoClient::Cache::Repository
Constructor Details
#initialize(config) ⇒ RedisRepository
Returns a new instance of RedisRepository.
10 11 12 13 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 10 def initialize(config) @config = config @adapter = @config.impressions_adapter end |
Instance Method Details
#add(matching_key, bucketing_key, split_name, treatment, time) ⇒ Object
15 16 17 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 15 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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 19 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
50 51 52 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 50 def batch get_impressions(@config.impressions_bulk_size) end |
#clear ⇒ Object
54 55 56 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 54 def clear get_impressions end |
#get_impressions(number_of_impressions = 0) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 39 def get_impressions(number_of_impressions = 0) @adapter.get_from_queue(key, number_of_impressions).map do |e| impression = JSON.parse(e, symbolize_names: true) impression[:i][:f] = impression[:i][:f].to_sym impression end rescue StandardError => e @config.logger.error("Exception while clearing impressions cache: #{e}") [] end |
#key ⇒ Object
58 59 60 |
# File 'lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb', line 58 def key @key ||= namespace_key('.impressions') end |