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
62
# File 'lib/googleauth/stores/redis_token_store.rb', line 51

def initialize options = {}
  super()
  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



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

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

#load(id) ⇒ Object



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

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

#store(id, token) ⇒ Object



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

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