Sha256: 4d0700695dfcc9ff5aa9d8c62f80423d9c35eabe0cbabbac413d8d8c7f439cd2
Contents?: true
Size: 1.83 KB
Versions: 2
Compression:
Stored size: 1.83 KB
Contents
module SplitIoClient module Cache module Repositories module Impressions class RedisRepository < Repository IMPRESSIONS_SLICE = 1000 def initialize(adapter, config) @adapter = adapter @config = config end # Store impression data in Redis def add(split_name, data) @adapter.add_to_set( namespace_key("impressions.#{split_name}"), data.merge(split_name: split_name).to_json ) end def add_bulk(key, treatments, time) @adapter.redis.pipelined do treatments.each_slice(IMPRESSIONS_SLICE) do |treatments_slice| treatments_slice.each do |split_name, treatment| add(split_name, 'key_name' => key, 'treatment' => treatment, 'time' => time) end end end end # Get random impressions from redis in batches of size @config.impressions_queue_size, # delete fetched impressions afterwards def clear impressions = impression_keys.each_with_object([]) do |key, memo| members = @adapter.random_set_elements(key, @config.impressions_queue_size) members.each do |impression| parsed_impression = JSON.parse(impression) memo << { feature: parsed_impression['split_name'], impressions: parsed_impression.reject { |k, _| k == 'split_name' } } end @adapter.delete_from_set(key, members) end impressions end private # Get all sets by prefix def impression_keys @adapter.find_sets_by_prefix(namespace_key('impressions.')) end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
splitclient-rb-3.1.0.pre.rc11 | lib/cache/repositories/impressions/redis_repository.rb |
splitclient-rb-3.1.0.pre.rc10 | lib/cache/repositories/impressions/redis_repository.rb |