Sha256: 3b17ee2d12a3c7dc73379ae462fa7b2b25d3f6ef5dff38ac6edef6e05b4261cc
Contents?: true
Size: 1.85 KB
Versions: 116
Compression:
Stored size: 1.85 KB
Contents
# frozen_string_literal: true module SplitIoClient module Cache module Repositories module Impressions class RedisRepository < ImpressionsRepository EXPIRE_SECONDS = 3600 def initialize(config) @config = config @adapter = @config.impressions_adapter end def add(matching_key, bucketing_key, split_name, treatment, time) add_bulk(matching_key, bucketing_key, { split_name => treatment }, time) end def add_bulk(matching_key, bucketing_key, treatments, time) impressions = treatments.map do |split_name, treatment| { m: metadata, 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 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 def batch get_impressions(@config.impressions_bulk_size) end def clear get_impressions end def key @key ||= namespace_key('.impressions') end end end end end end
Version data entries
116 entries across 116 versions & 1 rubygems