Skip to content

Commit

Permalink
interative attributes and site update
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Dec 10, 2024
1 parent c306d9b commit 189e88a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ you can simply link your program using the `-lredisx -lxchange` flags. Your `Ma

```make
myprog: ...
cc -o $@ $^ $(LDFLAGS) -lredisx -lxchange
$(CC) -o $@ $^ $(LDFLAGS) -lredisx -lxchange
```

(Or, you might simply add `-lredisx -lxchange` to `LDFLAGS` and use a more standard recipe.) And, in if you installed
Expand Down Expand Up @@ -321,6 +321,7 @@ The same goes for disconnect hooks, using `redisxAddDisconnectHook()` instead.
## Simple Redis queries
- [Interactive transactions](#interactive-transactions)
- [Bundled Attributes](#attributes)
- [Push notifications](#push-notifications)
- [RESP data type](#resp-data-type)
Expand Down Expand Up @@ -374,6 +375,28 @@ individual parameters are not 0-terminated strings.
In interactive mode, each request is sent to the Redis server, and the response is collected before the call returns
with that response (or `NULL` if there was an error).
<a name="attributes"></a>
### Bundled Attributes
Redis 6 introduced the possibility of sending optional attributes along with responses, using the RESP3 protocol.
These attributes are not included in the responses sent to users, in accordance with RESP3 protocol. Rather, they are
made available to users on demand, when needed, after the response to a request is received. You may retrieve the
attributes to interactive requests _after_ the `redisxRequest()` or `redisxArrayRequest()` queries, using
`redisxGetAttributes()`, e.g.:
```c
...
// Some interactive request
RESP *reply = redisxRequest(redis, ...);
// Get the attributes (if any) that were bundled with the response...
RESP *attributes = redisxGetAttributes(redis);
...
```


<a name="push-notifications"></a>
### Push notifications

Expand Down Expand Up @@ -891,7 +914,7 @@ Stay tuned.
## Advanced queries and pipelining

- [Asynchronous client processing](#asynchronous-client-processing)
- [Bundled Attributes](#attributes)
- [Bundled Attributes](#async-attributes)
- [Pipelined transactions](#pipelined-transactions)


Expand Down Expand Up @@ -976,7 +999,7 @@ Of course you can build up arbitrarily complex set of queries and deal with a se
what works best for your application.
<a name="attributes"></a>
<a name="async-attributes"></a>
### Bundled Attributes
As of Redis 6, the server might send ancillary data along with replies, if the RESP3 protocol is used. These are
Expand Down
1 change: 1 addition & 0 deletions include/redisx.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ void redisxClearDisconnectHooks(Redis *redis);

RESP *redisxRequest(Redis *redis, const char *command, const char *arg1, const char *arg2, const char *arg3, int *status);
RESP *redisxArrayRequest(Redis *redis, char *args[], int length[], int n, int *status);
RESP *redisxGetAttributes(Redis *redis);
int redisxSetValue(Redis *redis, const char *table, const char *key, const char *value, boolean confirm);
RESP *redisxGetValue(Redis*redis, const char *table, const char *key, int *status);
char *redisxGetStringValue(Redis *redis, const char *table, const char *key, int *len);
Expand Down
1 change: 1 addition & 0 deletions src/redisx-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ static void rPushMessageAsync(RedisClient *cl, RESP *resp) {
* @param cl The Redis client instance
* @return The attributes last received (possibly NULL).
*
* @sa redisxGetAttributes()
* @sa redisxClearAttributesAsync()
* @sa redisxReadReplyAsync()
* @sa redisxLockClient()
Expand Down
26 changes: 26 additions & 0 deletions src/redisx.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,32 @@ RESP *redisxArrayRequest(Redis *redis, char *args[], int lengths[], int n, int *
}


/**
* Returns a copy of the attributes sent along with the last interative request. The user should
* destroy the returned RESP after using it by calling redisxDestroyRESP().
*
* @param redis Pointer to a Redis instance.
* @return The attributes (if any) that were sent along with the last response on the
* interactive client.
*
* @sa redisxGetAttributeAsync()
* @sa redisxRequest()
* @sa redisxArrayRequest()
* @sa redisxDestroyRESP()
*/
RESP *redisxGetAttributes(Redis *redis) {
static const char *fn = "redisxGetAttributes";
RESP *attr;

if(redisxCheckValid(redis) != X_SUCCESS) return x_trace_null(fn, NULL);
if(redisxLockEnabled(redis->interactive) != X_SUCCESS) return x_trace_null(fn, NULL);

attr = redisxGetAttributesAsync(redis->interactive);
redisxUnlockClient(redis->interactive);

return attr;
}

/**
* Sets a user-defined function to process push messages for a specific Redis instance. The function's
* implementation must follow a simple set of rules:
Expand Down

0 comments on commit 189e88a

Please sign in to comment.