Create an interface to Redis, with a generated interface to all Redis commands.

hiredis(..., version = NULL)

redis_available(...)

Arguments

...

Named configuration options passed to redis_config, used to create the environment (notable keys include host, port, and the environment variable REDIS_URL). For redis_available, arguments are passed through to hiredis.

version

Version of the interface to generate. If given as a string to numeric version, then only commands that exist up to that version will be included. If given as TRUE, then we will query the Redis server (with INFO) and extract the version number that way.

Details

There is no need to explicitly close the redis connection. It will be closed automatically when the connection goes out of scope and is garbage collected.

Warning

Some commands will block. This includes BRPOP (and other list commands beginning with B). Once these commands have been started, they cannot be interrupted by Ctrl-C from an R session. This is because the redux package hands over control to a blocking function in the hiredis (C) library, and this cannot use R's normal interrupt machinery. If you want to block but retain the ability to interrupt then you will need to wrap this in another call that blocks for a shorter period of time:


  found <- NULL
  con <- redux::hiredis()
  found <- NULL
  while (is.null(found)) {
    found <- con$BLPOP("key", 1)
    Sys.sleep(0.01) # needed for R to notice that interrupt has happened
  }

Examples

# Only run if a Redis server is running
if (redux::redis_available()) {
  r <- redux::hiredis()
  r$PING()
  r$SET("foo", "bar")
  r$GET("foo")

  # There are lots of methods here:
  r
}
#> <redis_api>
#>   Redis commands:
#>     APPEND: function
#>     AUTH: function
#>     BGREWRITEAOF: function
#>     BGSAVE: function
#>     BITCOUNT: function
#>     BITFIELD: function
#>     BITOP: function
#>     BITPOS: function
#>     BLPOP: function
#>     BRPOP: function
#>     BRPOPLPUSH: function
#>     CLIENT_GETNAME: function
#>     CLIENT_KILL: function
#>     CLIENT_LIST: function
#>     CLIENT_PAUSE: function
#>     CLIENT_REPLY: function
#>     CLIENT_SETNAME: function
#>     CLUSTER_ADDSLOTS: function
#>     CLUSTER_COUNTKEYSINSLOT: function
#>     CLUSTER_COUNT_FAILURE_REPORTS: function
#>     CLUSTER_DELSLOTS: function
#>     CLUSTER_FAILOVER: function
#>     CLUSTER_FORGET: function
#>     CLUSTER_GETKEYSINSLOT: function
#>     CLUSTER_INFO: function
#>     CLUSTER_KEYSLOT: function
#>     CLUSTER_MEET: function
#>     CLUSTER_NODES: function
#>     CLUSTER_REPLICATE: function
#>     CLUSTER_RESET: function
#>     CLUSTER_SAVECONFIG: function
#>     CLUSTER_SETSLOT: function
#>     CLUSTER_SET_CONFIG_EPOCH: function
#>     CLUSTER_SLAVES: function
#>     CLUSTER_SLOTS: function
#>     COMMAND: function
#>     COMMAND_COUNT: function
#>     COMMAND_GETKEYS: function
#>     COMMAND_INFO: function
#>     CONFIG_GET: function
#>     CONFIG_RESETSTAT: function
#>     CONFIG_REWRITE: function
#>     CONFIG_SET: function
#>     DBSIZE: function
#>     DEBUG_OBJECT: function
#>     DEBUG_SEGFAULT: function
#>     DECR: function
#>     DECRBY: function
#>     DEL: function
#>     DISCARD: function
#>     DUMP: function
#>     ECHO: function
#>     EVAL: function
#>     EVALSHA: function
#>     EXEC: function
#>     EXISTS: function
#>     EXPIRE: function
#>     EXPIREAT: function
#>     FLUSHALL: function
#>     FLUSHDB: function
#>     GEOADD: function
#>     GEODIST: function
#>     GEOHASH: function
#>     GEOPOS: function
#>     GEORADIUS: function
#>     GEORADIUSBYMEMBER: function
#>     GET: function
#>     GETBIT: function
#>     GETRANGE: function
#>     GETSET: function
#>     HDEL: function
#>     HEXISTS: function
#>     HGET: function
#>     HGETALL: function
#>     HINCRBY: function
#>     HINCRBYFLOAT: function
#>     HKEYS: function
#>     HLEN: function
#>     HMGET: function
#>     HMSET: function
#>     HSCAN: function
#>     HSET: function
#>     HSETNX: function
#>     HSTRLEN: function
#>     HVALS: function
#>     INCR: function
#>     INCRBY: function
#>     INCRBYFLOAT: function
#>     INFO: function
#>     KEYS: function
#>     LASTSAVE: function
#>     LINDEX: function
#>     LINSERT: function
#>     LLEN: function
#>     LPOP: function
#>     LPUSH: function
#>     LPUSHX: function
#>     LRANGE: function
#>     LREM: function
#>     LSET: function
#>     LTRIM: function
#>     MGET: function
#>     MIGRATE: function
#>     MONITOR: function
#>     MOVE: function
#>     MSET: function
#>     MSETNX: function
#>     MULTI: function
#>     OBJECT: function
#>     PERSIST: function
#>     PEXPIRE: function
#>     PEXPIREAT: function
#>     PFADD: function
#>     PFCOUNT: function
#>     PFMERGE: function
#>     PING: function
#>     PSETEX: function
#>     PSUBSCRIBE: function
#>     PTTL: function
#>     PUBLISH: function
#>     PUBSUB: function
#>     PUNSUBSCRIBE: function
#>     QUIT: function
#>     RANDOMKEY: function
#>     READONLY: function
#>     READWRITE: function
#>     RENAME: function
#>     RENAMENX: function
#>     RESTORE: function
#>     ROLE: function
#>     RPOP: function
#>     RPOPLPUSH: function
#>     RPUSH: function
#>     RPUSHX: function
#>     SADD: function
#>     SAVE: function
#>     SCAN: function
#>     SCARD: function
#>     SCRIPT_DEBUG: function
#>     SCRIPT_EXISTS: function
#>     SCRIPT_FLUSH: function
#>     SCRIPT_KILL: function
#>     SCRIPT_LOAD: function
#>     SDIFF: function
#>     SDIFFSTORE: function
#>     SELECT: function
#>     SET: function
#>     SETBIT: function
#>     SETEX: function
#>     SETNX: function
#>     SETRANGE: function
#>     SHUTDOWN: function
#>     SINTER: function
#>     SINTERSTORE: function
#>     SISMEMBER: function
#>     SLAVEOF: function
#>     SLOWLOG: function
#>     SMEMBERS: function
#>     SMOVE: function
#>     SORT: function
#>     SPOP: function
#>     SRANDMEMBER: function
#>     SREM: function
#>     SSCAN: function
#>     STRLEN: function
#>     SUBSCRIBE: function
#>     SUNION: function
#>     SUNIONSTORE: function
#>     SYNC: function
#>     TIME: function
#>     TOUCH: function
#>     TTL: function
#>     TYPE: function
#>     UNLINK: function
#>     UNSUBSCRIBE: function
#>     UNWATCH: function
#>     WAIT: function
#>     WATCH: function
#>     ZADD: function
#>     ZCARD: function
#>     ZCOUNT: function
#>     ZINCRBY: function
#>     ZINTERSTORE: function
#>     ZLEXCOUNT: function
#>     ZRANGE: function
#>     ZRANGEBYLEX: function
#>     ZRANGEBYSCORE: function
#>     ZRANK: function
#>     ZREM: function
#>     ZREMRANGEBYLEX: function
#>     ZREMRANGEBYRANK: function
#>     ZREMRANGEBYSCORE: function
#>     ZREVRANGE: function
#>     ZREVRANGEBYLEX: function
#>     ZREVRANGEBYSCORE: function
#>     ZREVRANK: function
#>     ZSCAN: function
#>     ZSCORE: function
#>     ZUNIONSTORE: function
#>   Other public methods:
#>     clone: function
#>     command: function
#>     config: function
#>     initialize: function
#>     pipeline: function
#>     reconnect: function
#>     subscribe: function
#>     type: function
#>     version: function