Redis執行lua腳本,key不存在的返回值


Redis執行lua腳本,如果key不存在,則對應返回值為 false(boolean)

local val = redis.call('get', KEYS[1])
print(val)

 

Redis 到 Lua 的轉換表。

  • Redis integer reply -> Lua number / Redis 整數轉換成 Lua 數字
  • Redis bulk reply -> Lua string / Redis bulk 回復轉換成 Lua 字符串
  • Redis multi bulk reply -> Lua table (may have other Redis data types nested) / Redis 多條 bulk 回復轉換成 Lua 表,表內可能有其他別的 Redis 數據類型
  • Redis status reply -> Lua table with a single ok field containing the status / Redis 狀態回復轉換成 Lua 表,表內的 ok 域包含了狀態信息
  • Redis error reply -> Lua table with a single err field containing the error / Redis 錯誤回復轉換成 Lua 表,表內的 err 域包含了錯誤信息
  • Redis Nil bulk reply and Nil multi bulk reply -> Lua false boolean type / Redis 的 Nil 回復和 Nil 多條回復轉換成 Lua 的布爾值 false

Lua 到 Redis 的轉換表。

  • Lua number -> Redis integer reply (the number is converted into an integer) / Lua 數字轉換成 Redis 整數
  • Lua string -> Redis bulk reply / Lua 字符串轉換成 Redis bulk 回復
  • Lua table (array) -> Redis multi bulk reply (truncated to the first nil inside the Lua array if any) / Lua 表(數組)轉換成 Redis 多條 bulk 回復
  • Lua table with a single ok field -> Redis status reply / 一個帶單個 ok 域的 Lua 表,轉換成 Redis 狀態回復
  • Lua table with a single err field -> Redis error reply / 一個帶單個 err 域的 Lua 表,轉換成 Redis 錯誤回復
  • Lua boolean false -> Redis Nil bulk reply. / Lua 的布爾值 false 轉換成 Redis 的 Nil bulk 回復

從 Lua 轉換到 Redis 有一條額外的規則,這條規則沒有和它對應的從 Redis 轉換到 Lua 的規則:

  • Lua boolean true -> Redis integer reply with value of 1. / Lua 布爾值 true 轉換成 Redis 整數回復中的 1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM