有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 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驱动程序)然后您可以通过jedis.expire(key, time_after_expire_in_second)设置该键的TTL

       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).