Learn R Programming

rredis (version 1.7.0)

redisSetContext: redisSetContext

Description

Get or set the current active Redis connection environment.

Usage

redisSetContext( e = NULL) redisGetContext()

Arguments

e
An environment representing the new Redis server connection context returned by rediscConnect(returnRef=TRUE). The default value of NULL sets the context to the most recently established connection.

Value

NULL is invisibly returned.

Details

The rredis package stores information associated with a connection to a Redis server in an environment. The redisSetContext and redisSetContext functions help manage simultaneous connection to multiple Redis servers.

The redisSetContext function returns an environment representing the current active Redis connection. If there is no current active Redis connection, an environment is still returned, but without connection information.

The redisSetContext function replaces the current active environment. Any number of simultaneous connections to multiple Redis servers may be managed in this manner.

See Also

redisGetContext redisConnect

Examples

Run this code
## Not run: 
# # Open a connection to a Redis server on HOST1 and store its context:
# HOST1 <- redisConnect(host='HOST1', returnRef=TRUE)
# print(redisInfo())
# 
# # Initiate a new Redis context:
# HOST2 <- redisConnect(host='HOST2', returnRef=TRUE)
# # The connection to HOST2 is now active:
# print(redisInfo())
# 
# # We may now switch back and forth between the two active connections:
# redisSetContext(HOST1)
# print(redisInfo())
# redisSetContext(HOST2)
# print(redisInfo())
# redisClose()
# redisSetContext(HOST1)
# redisClose()
# ## End(Not run)

Run the code above in your browser using DataLab