请检查以下命令:
redis /tmp/redis.sock> set s1 String1
OK
redis /tmp/redis.sock> set s2 String2
OK
redis /tmp/redis.sock> set s3 String3
OK
redis /tmp/redis.sock> LPUSH list s1 s2 s3
(integer) 3
redis /tmp/redis.sock> LRANGE list 0 -1
1) "s3"
2) "s2"
3) "s1"
redis /tmp/redis.sock>
当我尝试推送redis列表中的变量时,该值被视为字符串。向列表中添加变量有什么解决方法吗?
谢谢。
发布于 2017-02-27 20:16:20
Redis列表中的元素是String。您不能嵌套数据结构或在它们之间创建引用。
发布于 2017-02-27 20:21:04
如果要使用变量,可以使用Lua
脚本,
eval "redis.call('lpush', 'list', KEYS[1], KEYS[2], KEYS[3])" 3 String1 String2 String4
参考this,
> eval "s1 = 'String1'" 0
> eval "s2 = 'String2'" 0
> eval "s3 = 'String3'" 0
> eval "redis.call('lpush', 'list', s1, s2, s3)" 0
Redis-cli可能不允许创建全局变量s1
、s2
和s3
。要获得权限,请参阅此https://stackoverflow.com/a/19998708/6048928
https://stackoverflow.com/questions/42484140
复制相似问题