RedisX v0.9
A simple, light-weight Redis database client
Loading...
Searching...
No Matches
redisx-script.c File Reference

Functions

int redisxLoadScript (Redis *redis, const char *script, char **sha1)
 
RESPredisxRunScript (Redis *redis, const char *sha1, const char **keys, const char **params)
 
int redisxRunScriptAsync (RedisClient *cl, const char *sha1, const char **keys, const char **params)
 

Detailed Description

Date
Created on Sep 5, 2024
Author
Attila Kovacs

Supporting functions for loading and LUA scripts on a Redis server.

Function Documentation

◆ redisxLoadScript()

int redisxLoadScript ( Redis redis,
const char *  script,
char **  sha1 
)

Loads a LUA script into Redis, returning its SHA1 hash to use as it's call ID.

Parameters
[in]redisPointer to a Redis instance.
[in]scriptString containing the full LUA script.
[out]sha1Buffer into which SHA1 key returned by Redis to use as call ID. (It must be at least 41 bytes, and will be string terminated). By default it will return an empty string.
Returns
X_SUCCESS (0) if the script has been successfully loaded into Redis, or X_NULL if the Redis instance is NULL X_NAME_INVALID if the script is NULL or empty. REDIS_UNEXPECTED_RESP if received a Redis reponse of the wrong type, or an error (<0) returned by redisxRequest().

References redisxCheckDestroyRESP(), redisxDestroyRESP(), redisxRequest(), RESP_BULK_STRING, RESP::value, x_error(), X_NULL, X_SUCCESS, and x_trace().

◆ redisxRunScript()

RESP * redisxRunScript ( Redis redis,
const char *  sha1,
const char **  keys,
const char **  params 
)

Runs a LUA script that has been loaded into the Redis database, returning the response received, or NULL if there was an error.

Parameters
redisThe Redis instance
sha1The SHA1 sum of the script that was previously loaded into the Redis DB.
keysA NULL-terminated array of Redis keywords, or NULL if the script does not take any keyword argument.
paramsA NULL-terminated array of additional parameters to pass onto the script, or NULL if the script does not take any parameters.
Returns
The response received from the script or the EVALSHA request, or NULL if there was an error.
See also
redisxRunScriptAsync()
redisxLoadScript()

References Redis::interactive, redisxLockConnected(), redisxReadReplyAsync(), redisxRunScriptAsync(), redisxUnlockClient(), X_SUCCESS, and x_trace_null().

◆ redisxRunScriptAsync()

int redisxRunScriptAsync ( RedisClient cl,
const char *  sha1,
const char **  keys,
const char **  params 
)

Send a request to runs a LUA script that has been loaded into the Redis database. This function should be called with the connected client's mutex locked. The call returns as soon as the request has been sent, without waiting for a response to come back.

Parameters
clThe Redis client channel on which to send the request to run the script
sha1The SHA1 sum of the script that was previously loaded into the Redis DB.
keysA NULL-terminated array of Redis keywords, or NULL if the script does not take any keyword argument.
paramsA NULL-terminated array of additional parameters to pass onto the script, or NULL if the script does not take any parameters.
Returns
X_SUCCESS (0) if successful or else X_NULL if the redis or sha1 parameters are NULL, or else an error code (<0) from redisxSendArrayRequestAsync().
See also
redisxRunScript()
redisxLoadScript()
redisxLockConnected()

References redisxSendArrayRequestAsync(), x_error(), X_NULL, and X_SUCCESS.