Learn R Programming

rredis (version 1.7.0)

redisConnect: Connect to a Redis server.

Description

Connect to an available Redis server on the specified port.

Usage

redisConnect(host = "localhost", port = 6379, password = NULL, returnRef = FALSE, nodelay=TRUE, timeout=2678399L)

Arguments

host
The Redis server host name or inet address (optional, character). The default value is "localhost".
port
The Redis port number (optional, numeric or integer). The default value is 6379L.
password
Redis authentication password.
returnRef
Set returnRef=TRUE to return the environment that contains the Redis connection state (see details). The default value is FALSE.
nodelay
Set nodelay=TRUE to use TCP_NODELAY (that is, to disbable the TCP Nagle algorithm). The default value is TRUE, see the details below.
timeout
Set the R connection timeout (in seconds). Beware that some OSes may treat very large values as zero: however the POSIX standard requires values up to 31 days to be supported.

Value

Errors are displayed if the function fails to connect to the specified Redis server. Disconnect from a connected server with redisClose.If returnRef is set to TRUE and no error occurs, a list describing the Redis connection will be returned. A future version of the package will use this feature to support multiple Redis connections with the attachRedis function.

Details

A running instance of a Redis server is required. Use `returnRef` to return the Redis connection state in an environment. Then use the `redisSetContext` function to switch environment state and manage multiple open Redis connections.

Set nodelay=TRUE to use the TCP_NODELY socket setting (disabling the TCP Nagle flow control algorithm) which can improve performance especially for rapid, non-pipelined small-sized transactions. We follow the convention of other popular Redis clients like the hiredis C library interface and use TCP_NODELAY as the default choice.

Note that Redis pipelining can also increase performance: redisSetPipeline(TRUE) (q.v.).

References

http://redis.io/commands

See Also

redisClose redisGetContext redisSetContext redisSetPipeline redisGetResponse

Examples

Run this code
## Not run: 
# redisConnect()
# redisSet('x',runif(5))
# redisGet('x')
# redisClose()
# ## End(Not run)

Run the code above in your browser using DataLab