java - spring data redis 超时设置无效的问题
PHP中文网
PHP中文网 2017-04-17 17:34:12
0
1
382

Long expireTime=redisTemplate.boundValueOps(key).getExpire();

        int countNow = Integer.valueOf(redisTemplate.boundValueOps(key).get());

获取超时时间expiretime 为0
但是我他妈的居然能拿到key对应的值,是不是redis存磁盘了,还是redis删除数据的机制原因?测试的能行,生产环境就不行了!!

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
迷茫

Redis server, cluster settings, master-slave, slave has no data, the reason is unknown. Use a virtual one to drift data to the main redis server. The set key is not visible on the main server. The virtual one cannot be played, but it can be retrieved. There is no data in the slave redis service. The key is that you can get the expiretime to be zero through the method, but you can get the value corresponding to the key. Now that there are other redis servers, where is the data stored? Why is the expire value zero, and can I still get the value corresponding to the key? ? ?
Finally, after shutting down the slave redis, restarting the master server, and pointing the IP to the master redis server, the problem was solved.
The reason is unknown.
Where did the data go?

Supplement:
If you set an unstable key with a key-value that has an expiration time, please pay attention! If you use the method of setting expiretime to 0 to delete the key, redis may not delete it immediately.
Use the hasKey method of spring data redis to determine whether the key exists, and then you will fall into a trap, because even if the expiretime is 0, the key may not have been deleted,
redis expires The key uses lazy expiration: when accessing the key, it is determined whether the key has expired. If it expires, expiration processing is performed. Secondly, volatile keys are sampled and tested every second. If there are expired keys, all expired keys are processed.
We have no idea what settings this patrol speed is related to and how efficient it is. Therefore, when you set an unstable key and use hasKey to make a judgment, please note that you need to obtain the expiration time of the key and then make a judgment yourself.

The first edition of "Redis Design and Implementation" has explanations of the principles. If you are interested, you can search for it

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