class Google::Auth::Stores::RedisTokenStore

Implementation of user token storage backed by Redis. Tokens are stored as JSON using the supplied key, prefixed with `g-user-token:`

Constants

DEFAULT_KEY_PREFIX

Public Class Methods

new(options = {}) click to toggle source

Create a new store with the supplied redis client.

@param [::Redis, String] redis

Initialized redis client to connect to.

@param [String] prefix

Prefix for keys in redis. Defaults to 'g-user-token:'

@note If no redis instance is provided, a new one is created and

the options passed through. You may include any other keys accepted
by %x`Redis.new`
# File lib/googleauth/stores/redis_token_store.rb, line 51
def initialize(options = {})
  redis = options.delete(:redis)
  prefix = options.delete(:prefix)
  case redis
  when Redis
    @redis = redis
  else
    @redis = Redis.new(options)
  end
  @prefix = prefix || DEFAULT_KEY_PREFIX
end

Public Instance Methods

delete(id) click to toggle source

(see Google::Auth::Stores::TokenStore#delete)

# File lib/googleauth/stores/redis_token_store.rb, line 76
def delete(id)
  key = key_for(id)
  @redis.del(key)
end
load(id) click to toggle source

(see Google::Auth::Stores::TokenStore#load)

# File lib/googleauth/stores/redis_token_store.rb, line 64
def load(id)
  key = key_for(id)
  @redis.get(key)
end
store(id, token) click to toggle source

(see Google::Auth::Stores::TokenStore#store)

# File lib/googleauth/stores/redis_token_store.rb, line 70
def store(id, token)
  key = key_for(id)
  @redis.set(key, token)
end

Private Instance Methods

key_for(id) click to toggle source

Generate a redis key from a token ID

@param [String] id

ID of the token

@return [String]

Redis key
# File lib/googleauth/stores/redis_token_store.rb, line 89
def key_for(id)
  @prefix + id
end