redis.connect: Manage connections to a Redis database

Description Usage Arguments Value Author(s) Examples

View source: R/redis.R

Description

redis.connect creates a new connection to a Redis database and returns the handle.

redis.clone clones an existing connection by creating a new connection to the same Redis server using exactly the same settings as the supplied connection. Optionally, the database can be changed if db is set.

redis.close closes a Redis database connection.

Usage

1
2
3
4
5
redis.connect(host = "localhost", port = 6379L, timeout = 30,
              reconnect = FALSE, retry = FALSE, db = getOption("redis.default.db", 0L),
	      password = NULL)
redis.clone(rc, db = NA)
redis.close(rc)

Arguments

host

name of the host to connect to or a path to the socket (if port is 0)

port

numeric, TCP port to connect to or 0 if a local (unix) socket is to be used instead (not supported on Windows, obviously).

timeout

numeric, timeout in seconds for requests (reals are supported for sub-second accuracy)

reconnect

logical, if TRUE then commands used on this connection will attempt to re-connect in case the connection is closed unexpectedly (e.g., due to a previous error).

retry

logical, if TRUE then commands will attempt to retry once on connection failure by closing the connection, re-connecting and re-trying. Only meaningful in conjunction with reconnect=TRUE.

db

integer, index of the database (keyspace) to use. The index 0 is the default and any other index will result in a SELECT command to be sent upon connection to select the desired database. For redis.clone this can also be NA in which case the same database is used as in rc.

password

string, password to use for authentication with the server or NULL if no authentication is used. The password is also used for implicit re-connects if enabled.

rc

Redis connection handle (as returned by redis.connect)

Value

redis.connect and redis.clone: an opaque handle to use for subsequent operations on the connection (object of the class redisConnection)

redis.close: NULL (invisibly)

Author(s)

Simon Urbanek

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## try connecting - 
c <- tryCatch(redis.connect(),
              error = function(e) {
                cat("Cannot connect",e$message, " - please start Redis\n")
                NULL
              })
if (!is.null(c)) { ## go ahead only if Redis is up and we got a connection
  print(redis.get(c, "foo"))
  print(redis.set(c, "foo", "bar"))
  print(redis.get(c, "foo"))
  redis.rm(c, "foo")
  redis.close(c)
}

s-u/rediscc documentation built on July 22, 2020, 2:18 a.m.