Sha256: c9926e73cca309d5b1410bc3f9567fe93e82efebaee28aa5821aebe6803a004c

Contents?: true

Size: 759 Bytes

Versions: 1

Compression:

Stored size: 759 Bytes

Contents

# frozen_string_literal: true

require_relative "base"

module SidekiqAlive
  module Redis
    # Wrapper for `redis` gem used by sidekiq < 7
    # https://github.com/redis/redis-rb
    class RedisGem < Base
      def set(key, time:, ex:)
        redis.set(key, time, ex: ex)
      end

      def get(key)
        redis.get(key)
      end

      def match(key)
        keys = []
        cursor = 0

        loop do
          cursor, found_keys = redis.scan(cursor, match: key, count: 1000)
          keys += found_keys if found_keys
          break if cursor.to_i == 0
        end
        keys
      end

      def delete(key)
        redis.del(key)
      end

      private

      def redis
        Sidekiq.redis { |redis| redis }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq_alive-2.2.2 lib/sidekiq_alive/redis/redis_gem.rb