Sha256: 106c430c42e953f59e85b87b683cfd91cf46a2279e9c39396e0ea8fc5cc55d54

Contents?: true

Size: 818 Bytes

Versions: 3

Compression:

Stored size: 818 Bytes

Contents

# coding: utf-8
# frozen_string_literal: true

module Stealth
  module Redis
    extend ActiveSupport::Concern

    included do
      private

      def get_key(key, expiration: Stealth.config.session_ttl)
        if expiration > 0
          getex(key, expiration)
        else
          $redis.get(key)
        end
      end

      def delete_key(key)
        $redis.del(key)
      end

      def getex(key, expiration=Stealth.config.session_ttl)
        $redis.multi do |pipeline|
          pipeline.expire(key, expiration)
          pipeline.get(key)
        end.last
      end

      def persist_key(key:, value:, expiration: Stealth.config.session_ttl)
        if expiration > 0
          $redis.setex(key, expiration, value)
        else
          $redis.set(key, value)
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stealth-2.0.0.beta7 lib/stealth/helpers/redis.rb
stealth-2.0.0.beta6 lib/stealth/helpers/redis.rb
stealth-2.0.0.beta5 lib/stealth/helpers/redis.rb