Class: Google::Auth::Stores::RedisTokenStore

Inherits:
TokenStore
  • Object
show all
Defined in:
lib/googleauth/stores/redis_token_store.rb

Overview

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

Constant Summary collapse

DEFAULT_KEY_PREFIX =
'g-user-token:'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RedisTokenStore

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 ‘Redis.new`

Create a new store with the supplied redis client.

Parameters:

  • redis (::Redis, String)

    Initialized redis client to connect to.

  • prefix (String)

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



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/googleauth/stores/redis_token_store.rb', line 51

def initialize(options = {})
  redis = options.delete(:redis)
  prefix = options.delete(:prefix)
  @redis = case redis
           when Redis
             redis
           else
             Redis.new(options)
           end
  @prefix = prefix || DEFAULT_KEY_PREFIX
end

Instance Method Details

#delete(id) ⇒ Object



76
77
78
79
# File 'lib/googleauth/stores/redis_token_store.rb', line 76

def delete(id)
  key = key_for(id)
  @redis.del(key)
end

#load(id) ⇒ Object



64
65
66
67
# File 'lib/googleauth/stores/redis_token_store.rb', line 64

def load(id)
  key = key_for(id)
  @redis.get(key)
end

#store(id, token) ⇒ Object



70
71
72
73
# File 'lib/googleauth/stores/redis_token_store.rb', line 70

def store(id, token)
  key = key_for(id)
  @redis.set(key, token)
end