Sha256: 002b62a5e2de807aa48dbe46c7acf5ecfcafe6c0293574868e84244c231761b5

Contents?: true

Size: 1.66 KB

Versions: 20

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  module Cache
    module Repositories
      module Impressions
        class RedisRepository < ImpressionsRepository
          EXPIRE_SECONDS = 3600

          def initialize(adapter)
            @adapter = 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 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

          def key
            @key ||= namespace_key('.impressions')
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
splitclient-rb-6.1.0-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.1.0 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.1.0.pre.rc2-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.1.0.pre.rc2 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.1.0.pre.rc1-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.1.0.pre.rc1 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.0.1-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.0.1 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.0.1.pre.rc2-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.0.1.pre.rc2 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.0.1.pre.rc1-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.0.1.pre.rc1 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.0.0-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-6.0.0 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-5.1.3.pre.rc4-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-5.1.3.pre.rc4 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-5.1.3.pre.rc3-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-5.1.3.pre.rc3 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-5.1.3.pre.rc2-java lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb
splitclient-rb-5.1.3.pre.rc2 lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb