Class: JWTea::Stores::RedisStore

Inherits:
Object
  • Object
show all
Defined in:
lib/jw_tea/stores/redis_store.rb

Constant Summary collapse

OK =
'OK'
TEMPLATE =
'jti:%<jti>s'

Instance Method Summary collapse

Constructor Details

#initialize(*redis_options) ⇒ RedisStore

Returns a new instance of RedisStore.



10
11
12
# File 'lib/jw_tea/stores/redis_store.rb', line 10

def initialize(*redis_options)
  @redis = ::Redis.new(*redis_options)
end

Instance Method Details

#delete(jti) ⇒ Object



25
26
27
28
29
# File 'lib/jw_tea/stores/redis_store.rb', line 25

def delete(jti)
  key = key(jti)
  result = @redis.del(key)
  result == 1
end

#exists?(jti, exp) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/jw_tea/stores/redis_store.rb', line 20

def exists?(jti, exp)
  key = key(jti)
  @redis.get(key) == exp.to_s
end

#save(jti, exp, ttl_in_seconds) ⇒ Object



14
15
16
17
18
# File 'lib/jw_tea/stores/redis_store.rb', line 14

def save(jti, exp, ttl_in_seconds)
  key = key(jti)
  result = @redis.setex(key, ttl_in_seconds, exp.to_s)
  result == OK
end