[英]How do I check if a key inside a hash exists (redis)?
How do I check if a key inside a hash exists (redis)? 如何检查哈希中的键是否存在(redis)?
I tried this way: 我这样尝试:
redisClient.exists(obj.mydict.user.toString().pos, function(err,reply) {
if(!err) {
if(reply !== null) {
...
however I get: 但是我得到:
node_redis: Deprecated: The EXISTS command contains a "undefined" argument.
This is converted to a "undefined" string now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you intended it to.
I do not know how. 我不知道怎么。 What I'm trying is to check if my .pos key exists in my hash obj.mydict.user.toString() , how would it do it in node_redis ? 我正在尝试检查.pos密钥是否存在于哈希obj.mydict.user.toString()中 ,它将如何在node_redis中进行 ?
虽然没有特定的命令来检查Redis哈希中字段是否存在,但是您可以调用HGET
并从nil
答复中推断出不存在。
How about using in? 使用in怎么样?
var hash = {'a': 1, 'b': 2};
console.log('a' in hash);
console.log('c' in hash);
// you can use 'hget' to check the existence of your key in particular hash like as follow:
client.hget('HASH NAME', 'mykey',function(err, result)
{
if(err)
console.log(err.message);
console.log(JSON.stringify(result));
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.