How do I check if a key inside a hash exists (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 ?
虽然没有特定的命令来检查Redis哈希中字段是否存在,但是您可以调用HGET
并从nil
答复中推断出不存在。
How about using 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));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.