Java 如何刷新令牌';s在redis中的SSO过期时间?

Java 如何刷新令牌';s在redis中的SSO过期时间?,java,web,redis,Java,Web,Redis,当客户端(浏览器)访问任何资源时,应更新令牌的过期时间(延迟),如何实现此要求? 使用拦截器或过滤器,并将令牌重新设置到redis server?有几种方法可以做到这一点 1。调整Redis服务器的配置 maxmemory策略将此替换为 # volatile-lru -> Evict using approximated LRU among the keys with an expire set. # allkeys-lru -> Evict any key using appro

当客户端(浏览器)访问任何资源时,应更新令牌的过期时间(延迟),如何实现此要求?
使用拦截器或过滤器,并将令牌重新设置到redis server?

有几种方法可以做到这一点

1。调整Redis服务器的配置


maxmemory策略
将此
替换为

# 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(redisjava驱动程序),那么您可以通过,
jedis.expire(key,expire后的时间,以秒为单位)设置该键的TTL



您正在使用哪个redis驱动程序?但何时刷新redis server中的令牌过期时间?如果您想延长每次访问的过期时间,请延长访问后的过期时间。
   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).