Trim21
V2EX  ›  问与答

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

  •  
  •   Trim21 · Sep 4, 2019 · 1916 views
    This topic created in 2532 days ago, the information mentioned may be changed or developed.
    有没有可能出现这种情况:

    一段 lua 在运行过程中, 用 ttl 命令检查了 key 的剩余存活时间, 然后准备做进一步操作, 结果这个时间中 key 过期被清理了?
    3 replies    2019-09-04 10:15:34 +08:00
    fuxinya
        1
    fuxinya  
       Sep 4, 2019 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  
       Sep 4, 2019 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  
       Sep 4, 2019
    那段 lua 太慢的话先把 ttl 续上几秒再执行。最好不要因为单条 lua 指令会 block 其它请求。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2383 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:09 · PVG 00:09 · LAX 09:09 · JFK 12:09
    ♥ Do have faith in what you're doing.