RedisX v1.0
A simple, light-weight Redis database client
Loading...
Searching...
No Matches
redisx-net.c File Reference

Functions

void rCloseClientAsync (RedisClient *cl)
 
int rConnectAsync (Redis *redis, boolean usePipeline)
 
void rDisconnectAsync (Redis *redis)
 
void * RedisPipelineListener (void *pRedis)
 
int redisxConnect (Redis *redis, boolean usePipeline)
 
void redisxDestroy (Redis *redis)
 
void redisxDisconnect (Redis *redis)
 
RedisredisxInit (const char *server)
 
boolean redisxIsConnected (Redis *redis)
 
int redisxReconnect (Redis *redis, boolean usePipeline)
 
int redisxSetHostname (Redis *redis, const char *host)
 
int redisxSetPort (Redis *redis, int port)
 
int redisxSetSocketTimeout (Redis *redis, int millis)
 
int redisxSetTcpBuf (Redis *redis, int size)
 
int rSetServerAsync (Redis *redis, const char *desc, const char *hostname, int port)
 

Detailed Description

Date
Created on Aug 26, 2024
Author
Attila Kovacs

Network layer management functions for the RedisX library.

Function Documentation

◆ rCloseClientAsync()

void rCloseClientAsync ( RedisClient * cl)

Closes the Redis client on the specified communication channel. This call assumes that the caller has an exlusive lock on the client.

Parameters
clPointer to the Redis client instance.

◆ rConnectAsync()

int rConnectAsync ( Redis * redis,
boolean usePipeline )

Same as rConnectClient() but called with the client's mutex already locked.

Parameters
redisPointer to a Redis instance.
usePipelineTRUE (non-zero) if a pipeline client should be connected also, or FALSE to create an interactive connection only.
Returns
X_SUCCESS (0) if successful, or X_ALREADY_OPEN if the Redis instance is alreast connected. X_NO_SERVICE if there was an error connecting to Redis, or else an error (<0) returned by rConnectClientAsync().
See also
rConnectClient()

References REDISX_INTERACTIVE_CHANNEL, REDISX_PIPELINE_CHANNEL, redisxErrorDescription(), and redisxIsConnected().

◆ rDisconnectAsync()

void rDisconnectAsync ( Redis * redis)

Same as rCloseClient() except without the exlusive locking mechanism of the client's IO.

Parameters
redisPointer to a Redis instance.

◆ RedisPipelineListener()

void * RedisPipelineListener ( void * pRedis)

The listener function that processes pipelined responses in the background. It is started when Redis is connected with the pipeline enabled.

Parameters
pRedisPointer to a Redis instance.
Returns
Always NULL.

References RESP::n, redisxCheckValid(), redisxDestroyRESP(), redisxReadReplyAsync(), RESP_SIMPLE_STRING, and RESP::type.

◆ redisxConnect()

int redisxConnect ( Redis * redis,
boolean usePipeline )

Connects to a Redis server.

Parameters
redisPointer to a Redis instance.
usePipelineTRUE (non-zero) if Redis should be connected with a pipeline client also, or FALSE (0) if only the interactive client is needed.
Returns
X_SUCCESS (0) if successfully connected to the Redis server. X_NO_INIT if library was not initialized via initRedis(). X_ALREADY_OPEN if already connected. X_NO_SERVICE if the connection failed. X_NULL if the redis argument is NULL.
See also
redisxInit()
redisxSetPort()
redisxSetUser()
redisxSetPassword()
redisxSetTcpBuf()
redisxSelectDB()
redisxDisconnect()

References rConnectAsync().

◆ redisxDestroy()

void redisxDestroy ( Redis * redis)

Destroys a Redis intance, disconnecting any clients that may be connected, and freeing all resources used by that Redis instance.

Parameters
redisPointer to a Redis instance.

References REDISX_CHANNELS, redisxClearSubscribers(), redisxDestroyRESP(), redisxDisconnect(), and redisxIsConnected().

◆ redisxDisconnect()

void redisxDisconnect ( Redis * redis)

Disconnect all clients from the Redis server.

Parameters
redisPointer to a Redis instance.

References rDisconnectAsync(), and redisxCheckValid().

◆ redisxInit()

Redis * redisxInit ( const char * server)

Initializes the Redis client library, and sets the hostname or IP address for the Redis server.

Parameters
serverServer host name or numeric IP address, e.g. "127.0.0.1". The string will be copied, not referenced, for the internal configuration, such that the string passed may be destroyed freely after the call.
Returns
X_SUCCESS or X_FAILURE if the IP address is invalid. X_NULL if the IP address is NULL.
See also
redisxInitSentinel()

References REDISX_CHANNELS, REDISX_DEFAULT_TIMEOUT_MILLIS, REDISX_INTERACTIVE_CHANNEL, REDISX_PIPELINE_CHANNEL, REDISX_RESP2, REDISX_SUBSCRIPTION_CHANNEL, REDISX_TCP_BUF_SIZE, and rSetServerAsync().

◆ redisxIsConnected()

boolean redisxIsConnected ( Redis * redis)

Checks if a Redis instance is connected.

Parameters
redisPointer to a Redis instance.
Returns
TRUE (1) if the Redis instance is connected, or FALSE (0) otherwise.

References redisxCheckValid().

◆ redisxReconnect()

int redisxReconnect ( Redis * redis,
boolean usePipeline )

Disconnects from Redis, and then connects again...

Parameters
redisPointer to a Redis instance.
usePipelineWhether to reconnect in pipelined mode.
Returns
X_SUCCESS (0) if successful X_NULL if the Redis instance is NULL

or else an error (<0) as would be returned by redisxConnect().

◆ redisxSetHostname()

int redisxSetHostname ( Redis * redis,
const char * host )

Changes the host name for the Redis server, prior to calling redisxConnect().

Parameters
redisPointer to a Redis instance.
hostNew host name or IP address to use.
Returns
X_SUCCESS (0) if successful, or else X_NULL if the redis instance or the host name is NULL, or X_NO_INIT if the redis instance is not initialized, X_ALREADY_OPEN if the redis instance is currently in a connected state, or X_FAILURE if Redis was initialized in Sentinel configuration.
See also
redisxSetPort()
redisxConnect()

References redisxIsConnected(), and rSetServerAsync().

◆ redisxSetPort()

int redisxSetPort ( Redis * redis,
int port )

Sets a non-standard TCP port number to use for the Redis server, prior to calling redisxConnect().

Parameters
redisPointer to a Redis instance.
portThe TCP port number to use.
Returns
X_SUCCESS (0) if successful, or else X_NULL if the redis instance is NULL, or X_NO_INIT if the redis instance is not initialized, X_ALREADY_OPEN if the Redis instance is lready connected to a server, or X_FAILURE if Redis was initialized in Sentinel configuration.
See also
redisxSetHostname()
redisxConnect()

References redisxIsConnected().

◆ redisxSetSocketTimeout()

int redisxSetSocketTimeout ( Redis * redis,
int millis )

Sets a socket timeout for future client connections on a Redis instance. Effectively this is a timeout for send() only. The timeout for interatvice replies is controlled separately via redisxSetReplyTimoeut().

If not set (or set to zero or a negative value), then the timeout will not be configured for sockets, and the system default timeout values will apply.

Parameters
redisThe Redis instance
millis[ms] The desired socket read/write timeout, or <0 for socket default.
Returns
X_SUCCESS (0) if successful, or else X_NULL if the redis instance is NULL, or X_NO_INIT if the redis instance is not initialized.
See also
redisxSetReplyTimeout()

References REDISX_DEFAULT_TIMEOUT_MILLIS.

◆ redisxSetTcpBuf()

int redisxSetTcpBuf ( Redis * redis,
int size )

Set the size of the TCP/IP buffers (send and receive) for future client connections.

Parameters
redisPointer to a Redis instance.
size(bytes) requested buffer size, or <= 0 to use default value
Returns
X_SUCCESS (0) if successful, or else X_NULL if the redis instance is NULL, or X_NO_INIT if the redis instance is not initialized, or X_FAILURE if Redis was initialized in Sentinel configuration.

◆ rSetServerAsync()

int rSetServerAsync ( Redis * redis,
const char * desc,
const char * hostname,
int port )

Configures a new server by name or IP address and port number for a given Redis instance

Parameters
redisA Redis instance
descThe type of server, e.g. "master", "replica", "sentinel-18"
hostnameThe new host name or IP address
portThe new port number, or &lt=0 to use the default Redis port.
Returns
X_SUCCESS (0) if successful or else an error code <0.

References REDISX_TCP_PORT.