我可以SET通过Redis的引擎在Redis中保存客户端IP 吗?
像这样的东西:
SET my_key $client_ip
Run Code Online (Sandbox Code Playgroud) 我需要HMGET从Lua脚本中使用Redis 并在以下代码中提取特定值.但是redis.call('HMGET', table_key, hkey1, hkey2, ...)返回一个扁平的阵列{hkey1, val1, hkey2, val2, ...}
要按键提取值,我写道:
local function flat_map_get(flat_map, hash_key)
local i = 1
while flat_map[i] do
if flat_map[i] == hash_key then
return flat_map[i+1]
end
i = i+2
end
end
Run Code Online (Sandbox Code Playgroud)
当然,随着使用量的增加,对此功能的多次调用显示出主要的性能下降.
什么是从返回的平面数组中读取值的有效方法HMGET?或者,将返回的值转换为正确的键值表?
我已经阅读了 redis 配置文档,但找不到这样的选项。
我搜索并发现“默认情况下,密钥将永远存在”。我想急切地改变这种默认行为。
Normally Redis keys are created without an associated time to live. The key will simply live forever, unless it is removed by the user in an explicit way, for instance using the DEL command.
The EXPIRE family of commands is able to associate an expire to a given key, at the cost of some additional memory used by the key. When a key has an expire set, Redis will make sure to remove the …Run Code Online (Sandbox Code Playgroud) 我在跑
save 600 1
Run Code Online (Sandbox Code Playgroud)
如果至少有 1 个键已更改,则在我的 redis-cli 上每 10 分钟保存一次,但是它给了我:
(error) ERR wrong number of arguments for 'save' command
Run Code Online (Sandbox Code Playgroud)
我从 redis 的官方网站上拿这个例子:http : //redis.io/topics/persistence
我究竟做错了什么?
我似乎在Redis中找不到找到以下命令的命令:
设置密钥(如果不存在),否则返回其值
有什么方法可以在一次交易中实现这一目标吗?