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.18.0.rc1 lib/fmrest/token_store/redis.rb
fmrest-core-0.17.1 lib/fmrest/token_store/redis.rb
fmrest-core-0.17.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.17.0.rc1 lib/fmrest/token_store/redis.rb
fmrest-core-0.16.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.15.2 lib/fmrest/token_store/redis.rb
fmrest-core-0.15.1 lib/fmrest/token_store/redis.rb
fmrest-core-0.15.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.14.0 lib/fmrest/token_store/redis.rb
fmrest-core-0.13.1 lib/fmrest/token_store/redis.rb
fmrest-core-0.13.0 lib/fmrest/token_store/redis.rb
fmrest-0.12.0 lib/fmrest/token_store/redis.rb
fmrest-0.11.1 lib/fmrest/token_store/redis.rb
fmrest-0.11.0 lib/fmrest/token_store/redis.rb
fmrest-0.10.1 lib/fmrest/token_store/redis.rb
fmrest-0.10.0 lib/fmrest/token_store/redis.rb
fmrest-0.9.0 lib/fmrest/token_store/redis.rb
fmrest-0.8.0 lib/fmrest/token_store/redis.rb
fmrest-0.7.1 lib/fmrest/token_store/redis.rb
fmrest-0.7.0 lib/fmrest/token_store/redis.rb