The XDEL
command in Redis is generally used for deleting a specific ID from a stream. This can be handy when you want to remove an erroneous or unneeded entry from your stream.
Here's how you can use the XDEL
command using redis-py, which is the Redis client in Python.
import redis r = redis.Redis(host='localhost', port=6379, db=0) stream_key = 'mystream' message_id = '0-1' # Add message to stream r.xadd(stream_key, {'field': 'value'}) # Delete message from stream r.xdel(stream_key, message_id)
In this example, we first connect to the Redis server running on localhost at port 6379. Then, we specify the key of the stream ('mystream') and the ID of the message to delete ('0-1'). After adding a message to the stream, we then delete it with the xdel
function.
Q: Can I delete multiple IDs from a stream at once?
A: Yes, you can specify multiple IDs in the xdel
command. Here's how:
r.xdel(stream_key, '0-1', '0-2', '0-3')
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.