V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Trim21
V2EX  ›  问与答

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

  •  
  •   Trim21 · 2019-09-04 04:34:43 +08:00 · 1366 次点击
    这是一个创建于 1689 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有没有可能出现这种情况:

    一段 lua 在运行过程中, 用 ttl 命令检查了 key 的剩余存活时间, 然后准备做进一步操作, 结果这个时间中 key 过期被清理了?
    3 条回复    2019-09-04 10:15:34 +08:00
    fuxinya
        1
    fuxinya  
       2019-09-04 08:12:51 +08:00 via Android
    参见 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
        2
    fuxinya  
       2019-09-04 08:23:09 +08:00 via Android
    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
        3
    Lax  
       2019-09-04 10:15:34 +08:00
    那段 lua 太慢的话先把 ttl 续上几秒再执行。最好不要因为单条 lua 指令会 block 其它请求。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1304 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:37 · PVG 01:37 · LAX 10:37 · JFK 13:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.