Skip to content

Commit

Permalink
README reorg and site update
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Dec 19, 2024
1 parent d5ca742 commit 6ef3a86
Showing 1 changed file with 55 additions and 52 deletions.
107 changes: 55 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Last Updated: 13 December 2024
- [Building RedisX](#building-redisx)
- [Command-line interface (`redisx-cli`)](#redisx-cli)
- [Linking your application against RedisX](#linking)
- [A simple example](#example)
- [Managing Redis server connections](#managing-redis-server-connections)
- [Simple Redis queries](#simple-redis-queries)
- [Accessing key / value data](#accessing-key-value-data)
Expand All @@ -48,6 +47,10 @@ Last Updated: 13 December 2024
<a name="introduction"></a>
## Introduction

- [A simple example](#example)
- [Features overview](#features)
- [Related links](#related-links)

__RedisX__ is a free, light-weight [Redis](https://redis.io) client library for C/C++. As such, it should work with
Redis forks / clones like [Dragonfly](https://dragonfly.io) or [Valkey](https://valkey.io) also. It supports both
interactive and pipelined Redis queries, managing and processing subscriptions, atomic execution blocks, and LUA
Expand All @@ -69,6 +72,56 @@ repository on GitHub.
There are no official releases of __RedisX__ yet. An initial 1.0.0 release is expected in late 2024 or early 2025.
Before then the API may undergo slight changes and tweaks. Use the repository as is at your own risk for now.

<a name="example"></a>
### A simple example

Below is a minimal example of a program snippet, which connects to a Redis server (without authentication) and runs a
simple `PING` comand with a message, printing out the result on the console, while also following best practices of checking
for errors, and handling them -- in this case by printing informative error messages:

```c
#include <redisx.h>

// Initialize for Redis server at 'my-server.com'.
Redis *redis = redisxInit("my-server.com");

// Connect to redis
if(redis != NULL && redisxConnect(redis, FALSE) == X_SUCCESS) {
// Execute 'PING "Hello World!"' on the server
RESP *reply = redisxRequest(redis, "PING", "Hello World!", NULL, NULL, NULL);

// Check that we got a response of the expected type (bulk string of any length)
if(redisxCheckRESP(reply, RESP_BULK_STRING, 0) == X_SUCCESS)
printf("%s\n", (char *) reply->value);
else
fprintf(stderr, "ERROR! bad response\n");

// Clean up
redisxDestroyRESP(reply);
redisxDisconnect(redis);
}
else {
perror("ERROR! could not connect");
}

// Free up the resources used by the 'redis' instance.
redisxDestroy(redis);
```
You may find more details about each step further below. And, of course there are a lot more options and features,
that allow you to customize your interactions with a Redis / Valkey server. But the basic principle, and the steps,
follow the same pattern in general:
1. [Initialize](#initializing) a Redis instance.
2. [Configure](#configuring) the server properties: port, authentication, socket parameters etc. (not shown in above example).
3. [Connect](#connecting) to the Redis / Valkey server.
4. Interact with the server: run queries [interactively](#simple-redis-queries) or in [batch mode](#pipelined-transactions), process [push notifications](#push-notifications), [publish](#broadcasting-messages) or [subscribe](#subscriptions)...
5. [Disconnect](#disconnecting) from the server.
And at every step, you should check for and [handle errors](#error-handling) as appropriate.
<a name="features"></a>
### Features overview
#### Generic API Features
Expand Down Expand Up @@ -104,6 +157,7 @@ Before then the API may undergo slight changes and tweaks. Use the repository as
| resubscribe on reconnect | no | |
<a name="related-links"></a>
### Related links
- [Redis commands](https://redis.io/docs/latest/commands/) (reference documentation)
Expand Down Expand Up @@ -227,57 +281,6 @@ myprog: ...
the __RedisX__ and/or __xchange__ libraries elsewhere, you can simply add their location(s) to `LD_LIBRARY_PATH` prior
to linking.


-----------------------------------------------------------------------------

<a name="example"></a>
## A simple example

Below is a minimal example of a program snippet, which connects to a Redis server (without authentication) and runs a
simple `GET` query, printing out the result on the console, while also following best practices of checking
for errors, and handling them -- in this case by printing informative error messages:

```c
#include <redisx.h>

// Initialize for Redis server at 'my-server.com'.
Redis *redis = redisxInit("my-server.com");

// Connect to redis
if(redis != NULL && redisxConnect(redis, FALSE) == X_SUCCESS) {
// Run 'GET my-key' query on the server
RESP *reply = redisxRequest(redis, "GET", "my-key", NULL, NULL, NULL);

// Check that we got a response of the expected type (bulk string of any length)
if(redisxCheckRESP(reply, REDIS_BULK_STRING, 0) == X_SUCCESS)
printf("the value is: %s\n", (char *) reply->value);
else
fprintf(stderr, "ERROR! bad response\n");

// Clean up
redisxDestroyRESP(reply);
redisxDisconnect(redis);
}
else {
perror("ERROR! could not connect");
}

// Free up the resources used by the 'redis' instance.
redisxDestroy(redis);
```

You may find more details about each step further below. And, of course there are a lot more options and features,
that allow you to customize your interactions with a Redis / Valkey server. But the basic principle, and the steps,
follow the same pattern in general:

1. [Initialize](#initializing) a Redis instance.
2. [Configure](#configuring) the server properties: port, authentication, socket parameters etc. (not shown in above example).
3. [Connect](#connecting) to the Redis / Valkey server.
4. Interact with the server: run queries [interactively](#simple-redis-queries) or in [batch mode](#pipelined-transactions), process [push notifications](#push-notifications), [publish](#broadcasting-messages) or [subscribe](#subscriptions)...
5. [Disconnect](#disconnecting) from the server.

And at every step, you should check for and [handle errors](#error-handling) as appropriate.

-----------------------------------------------------------------------------

<a name="managing-redis-server-connections"></a>
Expand Down

0 comments on commit 6ef3a86

Please sign in to comment.