Class: Aliexpress::Token::RedisStore

Inherits:
Store
  • Object
show all
Defined in:
lib/aliexpress/token/redis_store.rb

Instance Attribute Summary

Attributes inherited from Store

#client

Instance Method Summary collapse

Methods inherited from Store

#authenticate, #authenticate_headers, #http_get_access_token, init_with, #initialize, #set_access_token

Constructor Details

This class inherits a constructor from Aliexpress::Token::Store

Instance Method Details

#access_tokenObject


25
26
27
28
29
30
# File 'lib/aliexpress/token/redis_store.rb', line 25

def access_token
  super
  client.access_token = weixin_redis.hget(client.redis_key, "access_token")
  client.expired_at   = weixin_redis.hget(client.redis_key, "expired_at")
  client.access_token
end

#refresh_tokenObject


15
16
17
18
19
20
21
22
23
# File 'lib/aliexpress/token/redis_store.rb', line 15

def refresh_token
  super
  weixin_redis.hmset(
    client.redis_key, "access_token",
    client.access_token, "expired_at",
    client.expired_at
  )
  weixin_redis.expireat(client.redis_key, client.expired_at.to_i-10) # 提前10秒超时
end

#token_expired?Boolean

Returns:

  • (Boolean)

11
12
13
# File 'lib/aliexpress/token/redis_store.rb', line 11

def token_expired?
  weixin_redis.hvals(client.redis_key).empty?
end

#valid?Boolean

Returns:

  • (Boolean)

6
7
8
9
# File 'lib/aliexpress/token/redis_store.rb', line 6

def valid?
 weixin_redis.del(client.redis_key)
 super
end

#weixin_redisObject


32
33
34
# File 'lib/aliexpress/token/redis_store.rb', line 32

def weixin_redis
  Configure.weixin_redis
end