Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
database::RedisClient Class Reference

A synchronous Redis client providing core operations. More...

#include <RedisClient.hpp>

Public Member Functions

 RedisClient (const std::string &host, int port)
 Constructs a new RedisClient.
 
 ~RedisClient ()
 
bool connect ()
 Connects to the Redis server.
 
void disconnect ()
 Disconnects from the Redis server.
 
std::string ping ()
 Sends a PING command to the Redis server.
 
bool set (const std::string &key, const std::string &value, int expire_seconds=0)
 Sets a key to hold a string value with an optional expiration time.
 
std::optional< std::string > get (const std::string &key)
 Gets the value of a key.
 
long long incr (const std::string &key)
 Increments the integer value of a key by one.
 
bool expire (const std::string &key, int seconds)
 Sets a timeout on a key.
 

Detailed Description

A synchronous Redis client providing core operations.

Constructor & Destructor Documentation

◆ RedisClient()

database::RedisClient::RedisClient ( const std::string &  host,
int  port 
)

Constructs a new RedisClient.

Parameters
hostThe Redis server hostname or IP address.
portThe Redis server port number.

◆ ~RedisClient()

database::RedisClient::~RedisClient ( )

Member Function Documentation

◆ connect()

bool database::RedisClient::connect ( )

Connects to the Redis server.

Returns
true if the connection was successful, false otherwise.

◆ disconnect()

void database::RedisClient::disconnect ( )

Disconnects from the Redis server.

◆ expire()

bool database::RedisClient::expire ( const std::string &  key,
int  seconds 
)

Sets a timeout on a key.

Parameters
keyThe key to set the timeout on.
secondsThe timeout in seconds.
Returns
true if the timeout was set, false otherwise.

◆ get()

std::optional< std::string > database::RedisClient::get ( const std::string &  key)

Gets the value of a key.

Parameters
keyThe key to query.
Returns
An optional string containing the value, or std::nullopt if the key does not exist.

◆ incr()

long long database::RedisClient::incr ( const std::string &  key)

Increments the integer value of a key by one.

Parameters
keyThe key to increment.
Returns
The value of the key after the increment.

◆ ping()

std::string database::RedisClient::ping ( )

Sends a PING command to the Redis server.

Returns
The response string from the server (e.g., "PONG").

◆ set()

bool database::RedisClient::set ( const std::string &  key,
const std::string &  value,
int  expire_seconds = 0 
)

Sets a key to hold a string value with an optional expiration time.

Parameters
keyThe key to set.
valueThe value to associate with the key.
expire_secondsOptional expiration time in seconds (0 means no expiration).
Returns
true if the command succeeded, false otherwise.

The documentation for this class was generated from the following files: