Redis 中的 lua 在运行过程中可能会出现 key 因为过期被清理的情况吗?

2019-09-04 04:34:43 +08:00
 Trim21
有没有可能出现这种情况:

一段 lua 在运行过程中, 用 ttl 命令检查了 key 的剩余存活时间, 然后准备做进一步操作, 结果这个时间中 key 过期被清理了?
1375 次点击
所在节点    问与答
3 条回复
fuxinya
2019-09-04 08:12:51 +08:00
参见 https://grokbase.com/t/gg/redis-db/1281v06jyr/keys-that-expire-in-lua-scripts

Since a whole Lua script execution is a single client command, Redis
will not actively expire keys while a Lua client script is being run.
fuxinya
2019-09-04 08:23:09 +08:00
but if the TTL runs out and the script attempts to
access the key, Redis will notice the key is expired and act as if
the key does not exist.
Lax
2019-09-04 10:15:34 +08:00
那段 lua 太慢的话先把 ttl 续上几秒再执行。最好不要因为单条 lua 指令会 block 其它请求。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/597708

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX