redis 對lua 指令碼傳出類型的理解

來源:互聯網
上載者:User

標籤:

 

Lua 到 Redis 的轉換表。

  • Lua number -> Redis integer reply (the number is converted into an integer)
  • Lua string -> Redis bulk reply
  • Lua table (array) -> Redis multi bulk reply (truncated to the first nil inside the Lua array if any)
  • Lua table with a single ok field -> Redis status reply
  • Lua table with a single err field -> Redis error reply
  • Lua boolean false -> Redis Nil bulk reply.

總結 redis 只認lua的number,string, table 的數組 , table.ok,table.err,從redis 的返回的類型也可以想到這一點。

也就是說你想這樣

return {name="foo", passwd="bar"} 這樣是不行的

也就是說 redis 為什麼要在lua 放進 cjson,cmsgpack庫的原因, 你傳複雜的類型出去只能這樣。

 

  • Lua table with a single ok field -> Redis status reply
  • Lua table with a single err field -> Redis error reply

對於這二種情況,我考慮是 不打算 使用 {ok="ok"} {err="err"} 這種形式,

我更加趨向使用redis.error_reply(error_string)和redis.status_reply(status_string).

因為這個更加抽象,改動就會少一些。

redis 對lua 指令碼傳出類型的理解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.