The XDEL
command in Redis is used to delete one or multiple entries from a stream. This is commonly used when you want to remove specific messages from a stream, such as removing old or irrelevant data.
Here's an example of using xDel
in PHP with the Predis client:
<?php require "vendor/autoload.php"; Predis\Autoloader::register(); try { $redis = new Predis\Client(); // Adding entries to a stream $redis->xadd('mystream', '*', 'field1', 'Hello'); // Delete an entry $redis->xdel('mystream', ['1526569495631-0']); } catch (Exception $e) { echo "Couldn't connected to Redis"; echo $e->getMessage(); } ?>
In this example, we first connect to the Redis server using Predis. We then add an entry to the stream 'mystream'. The xdel
command is used to delete an entry with a specific ID ('1526569495631-0') from the stream.
xdel
command and other Redis operations.1. Can I delete multiple entries at once with XDEL? Yes, you can pass an array of IDs to the XDEL command to delete multiple entries at once.
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.