my redis keys do not expire

我的未来我决定 提交于 2019-12-03 11:40:54

Since you're doing a '...' it's hard to say for sure, but I'd say you're setting mykey during that part, which will effectively remove the expiration.

From the EXPIRE manual

The timeout is cleared only when the key is removed using the DEL command or overwritten using the SET or GETSET commands

Also, regarding the -1 reply from TTL

Return value

Integer reply: TTL in seconds or -1 when key does not exist or does not have a timeout.

EDIT: Note that this behaviour changed in Redis 2.8

Starting with Redis 2.8 the return value in case of error changed:
The command returns -2 if the key does not exist.
The command returns -1 if the key exists but has no associated expire.

In other words, if your key exists, it would seem to be persistent, ie not have any expiration set.

EDIT: It seems I can reproduce this if I create the key on a REDIS slave server, the slave will not delete the key without master input, since normally you would not create keys locally on a slave. Is this the case here?

However while the slaves connected to a master will not expire keys independently (but will wait for the DEL coming from the master), they'll still take the full state of the expires existing in the dataset, so when a slave is elected to a master it will be able to expire the keys independently, fully acting as a master.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!