当客户端(浏览器)访问任何资源时,令牌的到期时间应该更新(延迟),如何实现此要求? 使用拦截器或过滤器,并将令牌重新设置为redis服务器?
答案 0 :(得分:1)
有几种方法可以做到。
<强> 1。调整Redis服务器的配置。 self descriptive redis.conf 强>
maxmemory-policy <POLICY>
将此<POLICY>
替换为
# volatile-lru -> Evict using approximated LRU among the keys with an expire set.
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
<强> 2。访问数据时更新ttl值。Jedis expire
如果您使用的是jedis(redis java驱动程序。),那么您可以设置该密钥的TTL,jedis.expire(key, time_after_expire_in_second)
;
expire(String key, int seconds)
Set a timeout on the specified key.
expireAt(String key, long unixTime)
EXPIREAT works exctly like EXPIRE but instead to get the number of seconds representing the Time To Live of the key as a second argument (that is a relative way of specifing the TTL), it takes an absolute one in the form of a UNIX timestamp (Number of seconds elapsed since 1 Gen 1970).