簡體   English   中英

如何檢查哈希中的鍵是否存在(redis)?

[英]How do I check if a key inside a hash exists (redis)?

如何檢查哈希中的鍵是否存在(redis)?

我這樣嘗試:

redisClient.exists(obj.mydict.user.toString().pos, function(err,reply) {
                if(!err) {
                    if(reply !== null) {
                    ...

但是我得到:

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.

我不知道怎么。 我正在嘗試檢查.pos密鑰是否存在於哈希obj.mydict.user.toString()中 ,它將如何在node_redis中進行

雖然沒有特定的命令來檢查Redis哈希中字段是否存在,但是您可以調用HGET並從nil答復中推斷出不存在。

使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM