EVAL script numkeys key [key ...] arg [arg ...]
可用版本>= 2.6.0 时间复杂度:依赖脚本的执行。
127.0.0.1:6379>eval "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 value1 value2 1) "key1" 2) "key2" 3) "value1" 4) "value2" 127.0.0.1:6379> eval "return {keys[1],keys[2],argv[1],argv[2]}" 2 key1 key2 value1 value2 (error) ERR Error running script (call to f_8cfd66635a33779a52579a216e55263704ce398a): @enable_strict_lua:15: user_script:1: Script attempted to access nonexistent global variable ‘keys‘
127.0.0.1:6379> eval "return redis.pcall(‘incr‘,‘key1‘)" 0 (integer) 3 127.0.0.1:6379> eval "return redis.call(‘incr‘,‘key1‘)" (integer) 4
127.0.0.1:6379> eval "return redis.call(‘set‘,KEYS[1],ARGV[1])" 1 hello world
OK 127.0.0.1:6379> get hello
"world"
127.0.0.1:6379> eval "return redis.call(‘incre‘,‘key1‘)" 0 (error) ERR Error running script (call to f_759ca743926970d3713f91641f418515a32ddafb): @user_script:1: @user_script: 1: Unknown Redis command called from Lua script 127.0.0.1:6379> eval "return redis.pcall(‘incre‘,‘key1‘)" 0
(error) @user_script: 1: Unknown Redis command called from Lua script
127.0.0.1:6379> eval "return false" 0 (nil) 127.0.0.1:6379> eval "return true" 0 (integer) 1 127.0.0.1:6379> eval "return {err=‘hello world‘}" 0 (error) hello world 127.0.0.1:6379> eval "return {ok=‘hello world‘}" 0 hello world
127.0.0.1:6379> eval "return ‘1233.233‘" 0 "1233.233" 127.0.0.1:6379> eval "return 1233.233" 0 (integer) 1233
127.0.0.1:6379> eval ‘return {12,234,nil,3,2}‘ 0 1) (integer) 12 2) (integer) 234
127.0.0.1:6379> eval "return {err=‘hello world‘}" 0 (error) hello world 127.0.0.1:6379> eval "return redis.error_reply(‘hello world‘)" 0
(error) hello world
127.0.0.1:6379> eval "return {ok=‘hello‘}" 0 hello 127.0.0.1:6379> eval "return redis.status_reply(‘hello‘)" 0 hello
127.0.0.1:6379> set key4 123 OK 127.0.0.1:6379> eval "return redis.pcall(‘get‘,KEYS[1])" 1 key4 "123" 127.0.0.1:6379> evalsha d7c9b2e2bdc79e3a69e21b26316bb62031861e13 1 key4## 这个是加上双引号的摘要 (error) NOSCRIPT No matching script. Please use EVAL.
127.0.0.1:6379> evalsha b8fadcd4ae40c7a8814847ab7a5e202b3bcca756 1 key4 "123"
127.0.0.1:6379> set key4 123 OK 127.0.0.1:6379> eval "return redis.pcall(‘get‘,KEYS[1])" 1 key4 "123" 127.0.0.1:6379> evalsha b8fadcd4ae40c7a8814847ab7a5e202b3bcca756 1 key4 "123" 127.0.0.1:6379> script flush OK 127.0.0.1:6379> evalsha b8fadcd4ae40c7a8814847ab7a5e202b3bcca756 1 key4 (error) NOSCRIPT No matching script. Please use EVAL. 127.0.0.1:6379> eval "return redis.pcall(‘get‘,KEYS[1])" 1 key4 "123"
127.0.0.1:6379> eval "return redis.pcall(‘get‘,KEYS[1])" 1 key4 "123" 127.0.0.1:6379> script exists b8fadcd4ae40c7a8814847ab7a5e202b3bcca756 1) (integer) 1 127.0.0.1:6379> script exists b8fadcd4ae40c7a8814847ab7a5e202b3bcca757 1) (integer) 0 127.0.0.1:6379> script flush OK 127.0.0.1:6379> script exists b8fadcd4ae40c7a8814847ab7a5e202b3bcca756 1) (integer) 0
127.0.0.1:6379>script flush OK 127.0.0.1:6379> script exists b8fadcd4ae40c7a8814847ab7a5e202b3bcca756 1) (integer) 0 127.0.0.1:6379> evalsha b8fadcd4ae40c7a8814847ab7a5e202b3bcca756 1 key4 (error) NOSCRIPT No matching script. Please use EVAL. 127.0.0.1:6379> script load "return redis.pcall(‘get‘,KEYS[1])" "b8fadcd4ae40c7a8814847ab7a5e202b3bcca756" 127.0.0.1:6379> evalsha b8fadcd4ae40c7a8814847ab7a5e202b3bcca756 1 key4 "123"
原文:https://www.cnblogs.com/--net/p/12805756.html