RcppRedis

RcppRedis provides R with an alternative to Bryan Lewis' wonderful rredis package. Both provide R with read and write access to the powerful and versatile Redis key-value store.

What is Redis?

Redis is a wickedly fast 'key-value' store. Sometimes it is also referred to as a 'data structure server'. It is very widely used across web companies: name one, and they probably use it.

It is also widely supported across languages offering data interchange between system with little effort. One can access Redis from the command-line, just about any scripting language, and most compiled languages. Redis is actively developed, and very well document. Just start at the Redis website.

What is rredis?

rredis is a package by Bryan Lewis which offers most (if not all) Redis commands from R. By cleverly utlising R's builtin-serialization, you can just say
redisConnect("some.server.net")               # if omitted, localhost is used
redisSet("mymodel",  lm(y ~ ., data=someDF))
and then in another session on either the same machine, or another machine, do
redisConnect("some.server.net")
fit <- redisGet("mymodel")
You can think of this as being similar to saveRDS() and readRDS(), only across the network (and hence saving disk access). It's very powerful, and very versatile. Plus, there are dozens of other commands for stacks, queues, lists, pub/sub communication and much more.

So why another package?

We wanted to store (irregular) time series in rredis, and the combination of repeated string-to-numeric conversion for both timestamps and values, plus the fact that we get the result set in a list we needed to concatenate into a vector, meant that performance was not quite what wanted.

Enter hiredis, the official C library for Redis, which along with Rcpp gives us an ability to easily used compiled code to do the same. Coupled with the recently-added package RApiSerialize package for native R serialization from C code, we have what is needed to perform a little better.

This is also illustrated in a complete example with timings in two recent presentations I gave about RcppRedis.

So in sum, the upside to RcppRedis is
  • use compiled code throughoyt
  • access to R native serialization as the C level
  • support for the Redis binary protocol avoiding string-to-numeric conversions

Current status

Working but incomplete. Only a few Redis commands are implemented, but the blue print for adding more is there. If you need other commands, consider contributing.

Thanks to John Buonagurio, we also have a Windows library for hiredis which Uwe Ligges added to the on the CRAN / win-builder machines. Simon Urbanek had already done the corresponding part for OS X, so the operating systems shipping pre-built packages all do so for CRAN.

Where does it live?

Sources for the RcppRedis package are in GitHub repo. The package is available via CRAN and its mirrors. Patches, pull requests, issue tickets etc are most welcome at the GitHub repo

Last modified: Mon Jun 9 19:17:32 CDT 2014