Class loon::RedisList¶
template <typename T>
A Redis-compatible list supporting operations from both ends. More...
#include <redis_list.hpp>
Public Functions¶
| Type | Name |
|---|---|
| RedisList () Constructs an empty RedisList . |
|
| RedisList (const RedisList & other) = default Copy constructor. |
|
| RedisList (RedisList && other) noexcept Move constructor. |
|
| RedisList (std::vector< T > && other) Constructs a RedisList from a vector by moving its elements. |
|
| bool | empty () const Checks if the list is empty. |
| size_t | llen () const Returns the length of the list (Redis LLEN command). |
| std::optional< T > | lpop () Removes and returns the first element (left pop). |
| std::vector< T > | lpop (size_t count) Removes and returns up to count elements from the front. |
| size_t | lpush (const T & value) Pushes a value to the front of the list (left push). |
| size_t | lpush (T && value) Pushes a value to the front of the list (left push). |
| std::vector< T > | lrange (int start, int stop) const Returns a range of elements without removing them. |
| RedisList & | operator= (const RedisList & other) = default Copy assignment operator. |
| RedisList & | operator= (RedisList && other) noexcept Move assignment operator. |
| std::optional< T > | rpop () Removes and returns the last element (right pop). |
| std::vector< T > | rpop (size_t count) Removes and returns up to count elements from the back. |
| size_t | rpush (const T & value) Pushes a value to the back of the list (right push). |
| size_t | rpush (T && value) Pushes a value to the back of the list (right push). |
| size_t | size () const Returns the number of elements in the list. |
| ~RedisList () = default Default destructor. |
Detailed Description¶
RedisList provides a double-ended queue with an API modeled after Redis list commands. It supports efficient O(1) push/pop operations at both ends and O(n) range queries.
Template parameters:
TElement type stored in the list.
loon::RedisList<std::string> list;
list.rpush("hello");
list.rpush("world");
auto val = list.lpop(); // returns "hello"
Public Functions Documentation¶
function RedisList [1/4]¶
Constructs an empty RedisList .
function RedisList [2/4]¶
Copy constructor.
function RedisList [3/4]¶
Move constructor.
function RedisList [4/4]¶
Constructs a RedisList from a vector by moving its elements.
Parameters:
otherVector to move elements from.
function empty¶
Checks if the list is empty.
Returns:
true if the list contains no elements, false otherwise.
function llen¶
Returns the length of the list (Redis LLEN command).
Returns:
The number of elements in the list.
function lpop [1/2]¶
Removes and returns the first element (left pop).
Returns:
The removed element, or std::nullopt if the list is empty.
function lpop [2/2]¶
Removes and returns up to count elements from the front.
Parameters:
countMaximum number of elements to remove.
Returns:
Vector of removed elements (may be smaller than count).
function lpush [1/2]¶
Pushes a value to the front of the list (left push).
Parameters:
valueThe value to push (copied).
Returns:
The new length of the list.
function lpush [2/2]¶
Pushes a value to the front of the list (left push).
Parameters:
valueThe value to push (moved).
Returns:
The new length of the list.
function lrange¶
Returns a range of elements without removing them.
Supports negative indices: -1 is the last element, -2 is second to last, etc. The range is inclusive on both ends (unlike typical C++ iterators).
Parameters:
startStarting index (inclusive, can be negative).stopEnding index (inclusive, can be negative).
Returns:
Vector of elements in the specified range, empty if invalid range.
list.lrange(0, -1); // Returns all elements
list.lrange(0, 2); // Returns first 3 elements
list.lrange(-3, -1); // Returns last 3 elements
function operator=¶
Copy assignment operator.
function operator=¶
Move assignment operator.
function rpop [1/2]¶
Removes and returns the last element (right pop).
Returns:
The removed element, or std::nullopt if the list is empty.
function rpop [2/2]¶
Removes and returns up to count elements from the back.
Parameters:
countMaximum number of elements to remove.
Returns:
Vector of removed elements (may be smaller than count).
function rpush [1/2]¶
Pushes a value to the back of the list (right push).
Parameters:
valueThe value to push (copied).
Returns:
The new length of the list.
function rpush [2/2]¶
Pushes a value to the back of the list (right push).
Parameters:
valueThe value to push (moved).
Returns:
The new length of the list.
function size¶
Returns the number of elements in the list.
Returns:
The number of elements in the list.
function ~RedisList¶
Default destructor.
The documentation for this class was generated from the following file include/loon/redis_list.hpp