Sha256: 0b8933593b56d99a16c0ac5ecb1d35c22f227ba487b674c1e930b08d7ff72c7b

Contents?: true

Size: 919 Bytes

Versions: 56

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

require "fmrest/token_store/base"
require "redis" unless defined?(MockRedis)

module FmRest
  module TokenStore
    class Redis < Base
      DEFAULT_PREFIX = "fmrest-token:".freeze

      STORE_OPTIONS = [:redis, :prefix].freeze

      def initialize(options = {})
        super
        @redis = @options[:redis] || ::Redis.new(options_for_redis)
        @prefix = @options[:prefix] || DEFAULT_PREFIX
      end

      def load(key)
        @redis.get(prefix_key(key))
      end

      def store(key, value)
        @redis.set(prefix_key(key), value)
        value
      end

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

      private

      def options_for_redis
        @options.dup.tap do |options|
          STORE_OPTIONS.each { |opt| options.delete(opt) }
        end
      end

      def prefix_key(key)
        "#{@prefix}#{key}"
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 2 rubygems

Version Path
fmrest-core-0.26.2 lib/fmrest/token_store/redis.rb
fmrest-core-0.26.1 lib/fmrest/token_store/redis.rb
fmrest-core-0.26.1.rc1 lib/fmrest/token_store/redis.rb
fmrest-core-0.26.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.26.0.rc1 lib/fmrest/token_store/redis.rb
fmrest-core-0.25.0.rc1 lib/fmrest/token_store/redis.rb
fmrest-core-0.24.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.24.0.rc1 lib/fmrest/token_store/redis.rb
fmrest-core-0.23.1 lib/fmrest/token_store/redis.rb
fmrest-core-0.23.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.22.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.21.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.21.0.rc1 lib/fmrest/token_store/redis.rb
fmrest-core-0.20.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.20.0.rc1 lib/fmrest/token_store/redis.rb
fmrest-core-0.19.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.19.0.rc1 lib/fmrest/token_store/redis.rb
fmrest-core-0.18.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.18.0.rc3 lib/fmrest/token_store/redis.rb
fmrest-core-0.18.0.rc2 lib/fmrest/token_store/redis.rb