11

I have a list of keys, and would like to delete all of them. No pattern matching, nothing, just simple delete. I don't want to run a loop, as there will be around 3-4k keys.

I was trying to pass a list into the delete function, but it didn't work

redis_keys = [key1,key2,key3,key4....keyn]
redis.delete(redis_keys)

In the docs it shows

enter image description here

but not how to pass multiple keys. On SO too all questions are related to deleting while matching keys with pattern, but not with exact keys available.

2 Answers 2

26

The *names syntax means that you can pass multiple variables via

redis.delete(*redis_keys)

which is really just a shorthand notation for

redis.delete(redis_keys[0], redis_keys[1], redis_keys[2], ..., redis_keys[-1])
Sign up to request clarification or add additional context in comments.

Comments

0

If you know the keys you want to delete, you can combine your lookup with your delete via something like this:

my_key = 'items.per.day.*'
redis.delete(*redis.keys(my_key))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.