#include <stdio.h>
#include <hiredis/hiredis.h>
int main() {
// Set the Redis server endpoint (replace "your_redis_server" and 6379 with your server's details)
const char *redis_server = "your_redis_server";
int redis_port = 6379;
// Connect to the Redis server
redisContext *context = redisConnect(redis_server, redis_port);
if (context == NULL || context->err) {
printf("Error: Unable to connect to Redis server\n");
return 1;
}
// Set a key-value pair in Redis
const char *key = "example_key";
const char *value = "example_value";
redisReply *reply = redisCommand(context, "SET %s %s", key, value);
freeReplyObject(reply);
// Retrieve the value for the key from Redis
reply = redisCommand(context, "GET %s", key);
printf("Value for key '%s': %s\n", key, reply->str);
freeReplyObject(reply);
// Disconnect from the Redis server
redisFree(context);
return 0;
}