"Redis" Key/Value Database Client

R client interface to the "Redis" key-value database.


Example

> redisConnect()         
> redisSet('foo', runif(10))
> bar <- redisGet('foo') 
> bar
 [1] 0.93499818 0.47159536 0.30597259 0.58325228 0.41589498 0.63914212
 [7] 0.34658694 0.08633471 0.18111369 0.15763507
 
> redisMSet(list(x=pi,y='Cazart',z=runif(2)))
> redisMGet(list('z','y'))
$z
[1] 0.1155711 0.7166137
 
$y
[1] "Cazart"

New in version 1.7.0

Better value exchange between R and Redis

We implemented a great suggestion by Simon Urbanek. Values obtained from Redis that are not serialized R objects are now decorated with an attribute named "redis string value." The package uses this to automatically maintain fidelity of the original Redis value through repeated download/upload cycles. Previous versions of the rredis package uploaded everything as serialized R values unless explictly told otherwise.

Consider the following interplay between the redis-cli client and R:

redis-cli set key "string value"

And now in R:

> library(rredis)
> redisConnect()
> redisGet("key")
[1] "string value"
attr(,"redis string value")     # <- note the new attribute
[1] TRUE
 
> redisSet("new key", redisGet("key"))

Recovering the "new key" value from the redis-cli client returns a string value now:

redis-cli get "new key"
"string value"

Before this change, users needed to be careful about converting strings to raw values in R. Now things work much more intuitively.

API change, and option to revert behavior

Set options('redis:num'=TRUE) to return Redis ":" messages as numeric values. This was the default behavior of the rredis package for all versions up to 1.6.9. For versions of the R package later than that, redis ":" messages are returned as raw Redis string values to correspond to the data types stored in Redis. Set this option to revert to the old behavior.

Redis commands affected by this option importantly include the increment and decrement operations. This change is outlined in the following example:

> library(rredis)
> redisConnect()
> redisSet('x',charToRaw('1'))
[1] "OK"

> redisIncr('x')
[1] "2"
attr(,"redis string value")
[1] TRUE

> options('redis:num'=TRUE)
> redisIncr('x')
[1] 3

> options('redis:num'=c())
> redisIncr('x')
[1] "4"
attr(,"redis string value")
[1] TRUE

Performance

Consider using the redisSetPipeline function to enable pipelining, and also read help about options available to the redisConnect function. Also see the available options in the redisConnect function.

Status

Travis CI status

News

1.7.0:

  • We implemented a great suggestion by Simon Urbanek. Values obtained from Redis that are not serialized R objects are now decorated with an attribute named "redis string value." The package uses this to automatically maintain fidelity of the original Redis value through repeated download/upload cycles. Previous versions of the rredis package uploaded everything as serialized R values unless explictly told otherwise.
  • Set options('redis:num'=TRUE) to return Redis ":" messages as numeric values. This was the default behavior of the rredis package for all versions up to 1.6.9. For versions of the R package later than that, redis ":" messages are returned as raw Redis string values to correspond to the data types stored in Redis. Redis commands affected by this option include all increment and decrement operations.

1.6.8.2:

  • The TCP Nagle disabling scheme has been improved. The default remains standard R connections.
  • A bug in the Lua script function 'redisEval' was fixed.

1.6.8:

  • The package now includes support for Redis bit operations thanks to code contributed by Kenny Helsens.
  • Wush Wu helped to add a new performance option on redisConnect to bring the rredis package closer to the performance of the hiredis C library. Use the nodelay=TRUE option to disable the TCP Nagle congestion control algorithm, which can dramatically improve performance especially for frequent short transactions, at the expense of basically allowing Redis to take over your network (diable TCP Nagle at your own risk, and only enable this option if you really need to). We include this option because that's what hiredis does by default (?!!), and we want to make this performance gain available. This TCP trickery unfortunately introduced a little bit of C code.
  • Use the redisCmd function to easily issue any Redis command, even if the R package does not yet have a wrapper function for it. Useul also for prototyping. This has been available for a while but people don't seem to know about it.
  • We've cut back and streamlined code when returning raw values and, based on a good suggestion of sherbert, there is now a unified way to return raw values across all functions that retrieve stored values from Redis. Simply add the raw=TRUE argument to skip unserialization of the returned result.

1.6.7:

  • Nonblocking connections in R are problematic, we switched to blocking mode.
  • Added redisBRPopLPush
  • Added connection timeout option to redisConnect
  • Added 'eval' lua scripting functions

1.6.6:

  • Fixed a bug in HMSet.

1.6.5:

  • Added missing HMGet function.
  • Added generic redis function.

1.6.3:

  • Support for new redisInfo format
  • Improved interrupt handling during communication
  • Minor man page fixes

Significant changes in version 1.6:

  • Transactions are supported.
  • Pub/sub is supported.
  • Better support for raw value types across the board.

Significant changes in version 1.4:

  • Many bugs were fixed in the sorted sets (redisZ*) functions.
  • New unit tests for sorted set functions were added.

Significant changes in version 1.2:

  1. We completely revamped communication with the Redis server, eliminating in-line messaging in anticipation of it's demise in future Redis versions. We also make a better effort to minimize copying by R prior to sending a message.

  2. Added support for Redis hashes and ordered sets. The R/Redis client now fully supports all Redis types.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rredis")

1.7.0 by B. W. Lewis, 4 years ago


Browse source code at https://github.com/cran/rredis


Authors: B. W. Lewis


Documentation:   PDF Manual  


Task views: High-Performance and Parallel Computing with R


Apache License (>= 2.0) license


Suggests RUnit


Depended on by doRedis.

Suggested by RcppRedis.


See at CRAN