// plain
The PHP Redis zrevrange command is used to get the elements of a sorted set with a score in a given range, sorted in descending order.
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->zadd('myzset', 1, 'one');
$redis->zadd('myzset', 2, 'two');
$redis->zadd('myzset', 3, 'three');
$values = $redis->zrevrange('myzset', 0, 1);
Array
(
[0] => three
[1] => two
)
$redis = new Redis();
- Create a new Redis instance.$redis->connect('127.0.0.1', 6379);
- Connect to Redis server.$redis->zadd('myzset', 1, 'one');
- Add an element to a sorted set, with a score of 1.$redis->zadd('myzset', 2, 'two');
- Add another element to the same sorted set, with a score of 2.$redis->zadd('myzset', 3, 'three');
- Add a third element to the same sorted set, with a score of 3.$values = $redis->zrevrange('myzset', 0, 1);
- Get the elements of the sorted set with a score between 0 and 1, sorted in descending order.
onelinerhub: How do I use the PHP Redis zrevrange command?