redis lua学習ノートhello world


helloを作成します.luaスクリプト
<span style="color:#330099;">local msg = "Hello, world!"
return msg</span>
./redis-cli EVAL  "$(cat hello.lua)"
  0
ハロー、worldに戻れ!
incr-and-storを作成するluaスクリプト
<span style="color:#330099;">local key1 = KEYS[1]
local key2 = KEYS[2]
local argv1 = ARGV[1]
local link_id = redis.call("INCR", key1)
redis.call("HSET", key2, link_id, argv1)
return link_id</span>
./redis-cli EVAL  "$(cat incr-and-stor.lua)"   2 links:counter links:urls www.sina.com
コマンド#コマンド#
 
luaスクリプト
KEYSテーブル長
個々のKEYS
個々のARGV
./redis-cli
EVAL
 "$(cat test2.lua)"
1
"XX"
10
 
 
 
 
 
 
リモートサービスであればeval前に-h-p-aなどのパラメータを追加
script loadとevalshaコマンドを使用する場合
先に使用
./redis-cli -h 192.168.1.21 -p xxxx -a xxxx SCRIPT LOAD "$(cat incr-and-stor.lua)"
「ada 6 c 37 ff 315095 bb 64765 d 5 e 6 b 8808 b 6 d 971 a 3 a」を返します.
そして
./redis-cli -h 192.168.1.21 -p xxxx -a xxxx EVALSHA "ada6c37ff315095bb64765d5e6b8808b6d971a3a"2 links:counter links:urls www.sina.com