Skip to content

Class loon::RedisList

template <typename T>

ClassList > loon > RedisList

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:

  • T Element 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 .

inline explicit loon::RedisList::RedisList () 


function RedisList [2/4]

Copy constructor.

loon::RedisList::RedisList (
    const RedisList & other
) = default


function RedisList [3/4]

Move constructor.

loon::RedisList::RedisList (
    RedisList && other
) noexcept


function RedisList [4/4]

Constructs a RedisList from a vector by moving its elements.

inline explicit loon::RedisList::RedisList (
    std::vector< T > && other
) 

Parameters:

  • other Vector to move elements from.

function empty

Checks if the list is empty.

inline bool loon::RedisList::empty () const

Returns:

true if the list contains no elements, false otherwise.


function llen

Returns the length of the list (Redis LLEN command).

inline size_t loon::RedisList::llen () const

Returns:

The number of elements in the list.


function lpop [1/2]

Removes and returns the first element (left pop).

inline std::optional< T > loon::RedisList::lpop () 

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.

inline std::vector< T > loon::RedisList::lpop (
    size_t count
) 

Parameters:

  • count Maximum 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).

inline size_t loon::RedisList::lpush (
    const T & value
) 

Parameters:

  • value The 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).

inline size_t loon::RedisList::lpush (
    T && value
) 

Parameters:

  • value The value to push (moved).

Returns:

The new length of the list.


function lrange

Returns a range of elements without removing them.

inline std::vector< T > loon::RedisList::lrange (
    int start,
    int stop
) const

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:

  • start Starting index (inclusive, can be negative).
  • stop Ending 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.

RedisList & loon::RedisList::operator= (
    const RedisList & other
) = default


function operator=

Move assignment operator.

RedisList & loon::RedisList::operator= (
    RedisList && other
) noexcept


function rpop [1/2]

Removes and returns the last element (right pop).

inline std::optional< T > loon::RedisList::rpop () 

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.

inline std::vector< T > loon::RedisList::rpop (
    size_t count
) 

Parameters:

  • count Maximum 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).

inline size_t loon::RedisList::rpush (
    const T & value
) 

Parameters:

  • value The 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).

inline size_t loon::RedisList::rpush (
    T && value
) 

Parameters:

  • value The value to push (moved).

Returns:

The new length of the list.


function size

Returns the number of elements in the list.

inline size_t loon::RedisList::size () const

Returns:

The number of elements in the list.


function ~RedisList

Default destructor.

loon::RedisList::~RedisList () = default



The documentation for this class was generated from the following file include/loon/redis_list.hpp