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);
}
}
巴扎黑2017-06-19 09:09:18
You will know if it is correct by trying it. What you need is not answers, you need encouragement.
阿神2017-06-19 09:09:18
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
怪我咯2017-06-19 09:09:18
Experiments are your best teachers, if you don’t see any problems when looking at the code
滿天的星座2017-06-19 09:09:18
Thank you everyone, it’s OK. I installed a Linux virtual machine and tested it