question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

delete() take in a list of keys

See original GitHub issue

The 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:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brejoccommented, Jan 30, 2017

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.

1reaction
woozykingcommented, Apr 14, 2015

It is pythonic, but when you do conn.delete(*list_of_keys), list_of_keys must not be empty or it’ll raise ResponseError: 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found