2017-10-18 225 views
-1

如何檢查散列中的密鑰是否存在(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

回答

1

如何使用?

var hash = {'a': 1, 'b': 2}; 
console.log('a' in hash); 
console.log('c' in hash); 
+0

所以,這樣我做了,但是我不得不搜索redis中的所有散列,我只是想檢查銀行中是否有密鑰。從我在這裏看到的文檔中看到的 – PerduGames

+0

,似乎沒有。所以方法是:'redisClient.hgetall(obj.mydict.user.toString(),function(err,reply){if(!err){if(「pos」in reply){...' – PerduGames

2

雖然沒有具體的命令在一個Redis的哈希檢查現場存在,你可以調用HGETnil回覆推斷不存在。

相關問題