java - How to set expiration time for Redis hashes
黄舟
黄舟 2017-06-19 09:07:18
0
4
1439

Use Redis to store some authentication information of active users to facilitate quick login. The user's information is of the hashes type, and the user's uid is used as the key. However, if the user has not logged in for a long time, it should be removed from Redis. I checked. The method I came across is to use the expire method of Jedis. I wrote a method myself, but I don’t know if it is correct.

public Long expire(String key, int time)
  {
    Jedis jedis = null;
    Long rs;
    
    try {
      jedis = pool.getResource();
      rs = jedis.expire(key, time);
      return rs;
    } catch (Exception e) {
      e.printStackTrace();
      return 0L;
    } finally {
      returnResource(jedis);
    }
  }
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
巴扎黑

You will know if it is correct by trying it. What you need is not answers, you need encouragement.

阿神

What you lack is a verification tool. If you are familiar with Redis commands, you can use the command line redis-cli. If you are not familiar with it, you can use graphical tools, such as Redis Desktop Manager

刘奇

Experiments are your best teachers, if you don’t see any problems when looking at the code

滿天的星座

Thank you everyone, it’s OK. I installed a Linux virtual machine and tested it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template