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:'



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/googleauth/stores/redis_token_store.rb', line 36

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



62
63
64
65
# File 'lib/googleauth/stores/redis_token_store.rb', line 62

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

#load(id) ⇒ Object



50
51
52
53
# File 'lib/googleauth/stores/redis_token_store.rb', line 50

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

#store(id, token) ⇒ Object



56
57
58
59
# File 'lib/googleauth/stores/redis_token_store.rb', line 56

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