A synchronous Redis client providing core operations.
More...
#include <RedisClient.hpp>
|
| | 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.
|
| |
A synchronous Redis client providing core operations.
◆ RedisClient()
| database::RedisClient::RedisClient |
( |
const std::string & |
host, |
|
|
int |
port |
|
) |
| |
Constructs a new RedisClient.
- Parameters
-
| host | The Redis server hostname or IP address. |
| port | The Redis server port number. |
◆ ~RedisClient()
| database::RedisClient::~RedisClient |
( |
| ) |
|
◆ 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
-
| key | The key to set the timeout on. |
| seconds | The 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
-
- 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
-
- 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
-
| key | The key to set. |
| value | The value to associate with the key. |
| expire_seconds | Optional 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: