Redis Python - how to delete all keys according to a specific pattern In python, without python iterating
I think the
for key in x: cache.delete(key)
is pretty good and concise. delete
really wants one key at a time, so you have to loop.
Otherwise, this previous question and answer points you to a lua-based solution.
How to remove all elements in Redis
You're storing in Redis an object (dict_
) under the key called 'pythonDict'. Just call cli.delete("pythonDict")
to delete it.
How to delete all keys in Redis matching pattern from within redis-cli repl?
Run this command inside redis-cli :
EVAL "return redis.call('del', unpack(redis.call('keys', ARGV[1])))" 0 prefix:*
Replace prefix:*
with your required pattern. The output will be the number of keys deleted.
Deleting multiple keys in python-Redis in single command
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])
How to atomically delete keys matching a pattern using Redis
Starting with redis 2.6.0, you can run lua scripts, which execute atomically. I have never written one, but I think it would look something like this
EVAL "return redis.call('del', unpack(redis.call('keys', ARGV[1])))" 0 prefix:[YOUR_PREFIX e.g delete_me_*]
Warning: As the Redis document says, because of performance maters,
keys
command should not use for regular operations in production, this
command is intended for debugging and special operations. read
more
See the EVAL documentation.
Related Topics
How to Increase the Font Size of the Markdown Table in Jupyter Notebook
Python: Assign Labels to Values in an Array
Sum of Square Differences (Ssd) in Numpy/Scipy
Print 5 Items in a Row on Separate Lines for a List
How to Get the Current Ipython/Jupyter Notebook Name
Pandas: Difference Between Pivot and Pivot_Table. Why Is Only Pivot_Table Working
Check Type: How to Check If Something Is a Rdd or a Dataframe
Python Strip Hyphen from Block of String
Running Two Python Scripts With Bash File
How to Replace Negative Numbers in Pandas Data Frame by Zero
How to Skip Empty Dates (Weekends) in a Financial Matplotlib Python Graph
How to Build Reports With Python Pandas
Split Large Text File(Around 50Gb) into Multiple Files
Converting Numpy Dtypes to Native Python Types
How to Add Pandas Data to an Existing CSV File
Python - Remove Any Element from a List of Strings That Is a Substring of Another Element