Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';t在Redis中从哈希中删除密钥_Python_Hash_Redis - Fatal编程技术网

Python Can';t在Redis中从哈希中删除密钥

Python Can';t在Redis中从哈希中删除密钥,python,hash,redis,Python,Hash,Redis,我在redis数据库中创建了一个散列,并在其中放入了一些键及其值。我现在想删除散列中的所有内容。我正在使用hdel,但无法使其正常工作。我对hdel(…)中应该包含的内容感到困惑,文档对我没有帮助。现在我有以下内容: test_hash = redis_cache.hgetall(hash_name) for key,value in test_hash.items(): i = redis_cache.hdel(hash_name,*key) 在hdel中。()我尝试

我在redis数据库中创建了一个散列,并在其中放入了一些键及其值。我现在想删除散列中的所有内容。我正在使用hdel,但无法使其正常工作。我对hdel(…)中应该包含的内容感到困惑,文档对我没有帮助。现在我有以下内容:

test_hash = redis_cache.hgetall(hash_name)
    for key,value in test_hash.items():
        i = redis_cache.hdel(hash_name,*key)
在hdel中。()我尝试了许多不同的方法,但似乎没有任何效果。在代码“删除”哈希中的所有内容后,我仍然可以执行redis_cache.hgetall()并获得相同的键和值。
有人知道更多吗?我正在使用Python。

好的,我发现我做错了什么。我必须创建密钥列表并执行以下操作:

    list = []
    for key,value in test_hash.items():
        list.append(key)
    i = redis_cache.hdel(hash_name,*list)