rcppredis_connection: RcppRedis interface

View source: R/rcppredis.R

rcppredis_connectionR Documentation

RcppRedis interface

Description

Support for using RcppRedis with RedisAPI.

Usage

rcppredis_connection(config = redis_config())

rcppredis_hiredis(..., version = NULL)

rcppredis_available(...)

Arguments

config

A named list of configuration options, as generated by redis_config. Only host and port are used at present.

...

arguments passed through to redis_config. Can include a named argument config or named arguments host, port.

version

Version of the RedisAPI to generate. If given as a numeric version (or something that can be coerced into one. If given as TRUE, then we query the Redis server for its version and generate only commands supported by the server.

Differences to redux/rrlite

Note that via this interface RcppRedis will not support binary serialisation (even though it does through its own interface) so you need to use object_to_string/string_to_object rather than object_to_bin/bin_to_object.

Treatment of TRUE/FALSE is different as redux will store them as 1/0 but RcppRedis will store as "TRUE"/"FALSE". Both will be converted back to TRUE/FALSE after as.logical though.

RcppRedis returns strings for Redis statuses (which are just strings) but redux/rrlite add a redis_status attribute. You'll see this most obviously with the printing of OK following a successful SET.

The rcppredis_available function is a simple test that can be used to detect if RcppRedis is available on a system. It will return TRUE if RcppRedis is installed, and if passing ... through to rcppredis_hiredis can create a Redis connection. This will fail if the Redis database cannot be reached, or if the Redis server requires authentication (which is not handled in this interface).

Examples

if (rcppredis_available()) {
  # This is the main entry point to use:
  con <- rcppredis_hiredis()

  # The returned object has many methods:
  con

  # Because RedisAPI provides the full API you can avoid using
  # functions like "KEYS" (which can block the Redis server)
  #    con$KEYS("*")
  # and instead use SCAN:
  con$SCAN(0, "*")

  # This pattern is formalised by the "scan_find" function (see
  # ?scan_find).
  scan_find(con, "*")
}

ropensci/RedisAPI documentation built on May 18, 2022, 9:46 a.m.