delete() take in a list of keys
See original GitHub issueThe use case came up when I tried to do this:
# conn is a valid StrictRedis instance
keys = conn.keys('namespace:*') # this returns a list
conn.delete(keys) # does not delete all the keys in the list
conn.delete(*keys) # raises ResponseError: wrong number of arguments for 'del' command
# edit: conn.delete(*keys) works when the list is not empty
Can we make it a bit neater to allow delete to just accept a list or a set of strings (keys) to do the necessary check to be passed to execute_command('DEL', ...)?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How can I remove a key from a Python dictionary?
To delete a key regardless of whether it is in the dictionary, use the two-argument form of dict.pop() : my_dict.pop('key', None).
Read more >Python Remove Key from a Dictionary: A Complete Guide
To remove a key from a dictionary in Python, use the pop() method or the “del” keyword. Both methods work the same in...
Read more >Python | Remove multiple keys from dictionary - GeeksforGeeks
In this method, we just use the Python pop() function which is used to remove a single key along with the list comprehension...
Read more >How to Remove a Key from a Python Dictionary – Delete Key ...
In this blog post, we will learn how to delete "keys" using two methods: 1. ... Keys map to their corresponding item in...
Read more >Python: Remove Key from Dictionary (4 Different Ways) - Datagy
Python makes it easy to remove multiple keys from a dictionary. The safest way of doing this is to loop over a list...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I ran into this issue last week in the context of the redis returner in SaltStack. It took me some time to dig out the true source for this error, because I was not aware, that Salt tried to pass an empty list. A slightly modified error message would have been a huge benefit.
It is pythonic, but when you do
conn.delete(*list_of_keys),list_of_keysmust not be empty or it’ll raiseResponseError: wrong number of arguments for 'del' command.I’m just proposing for a slightly more convenient interface for users who can just pass in a list or a set of strings to be deleted.