Redis 指令碼
Redis 指令碼
Redis 指令碼使用 Lua 直譯器來執行指令碼。 Redis 2.6 版本通過內嵌支援 Lua 環境。執行指令碼的常用命令為 EVAL。
語法
Eval 命令的基本語法如下:
redis 127.0.0.1:6379> EVAL script numkeys key [key ...] arg [arg ...]
例項
以下例項演示了 redis 指令碼工作過程:
redis 127.0.0.1:6379> EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second 1) "key1" 2) "key2" 3) "first" 4) "second"
Redis 指令碼命令
下表列出了 redis 指令碼常用命令:
序號 | 命令及描述 |
---|---|
1 | EVAL script numkeys key [key ...] arg [arg ...] 執行 Lua 指令碼。 |
2 | EVALSHA sha1 numkeys key [key ...] arg [arg ...] 執行 Lua 指令碼。 |
3 | SCRIPT EXISTS script [script ...] 檢視指定的指令碼是否已經被儲存在快取當中。 |
4 | SCRIPT FLUSH 從指令碼快取中移除所有指令碼。 |
5 | SCRIPT KILL 殺死當前正在執行的 Lua 指令碼。 |
6 | SCRIPT LOAD script 將指令碼 script 新增到指令碼快取中,但並不立即執行這個指令碼。 |