Learn R Programming

rredis: An R client for Redis

Example

> library(rredis)
> 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

Copy Link

Version

Install

install.packages('rredis')

Monthly Downloads

118

Version

1.7.0

License

Apache License (>= 2.0)

Maintainer

Last Published

July 5th, 2015

Functions in rredis (1.7.0)

redisBRPop

Blocking List Pop
redisDelete

Delete a key and associated value from Redis.
redisExpire

Set a timeout on the specified key.
redisGetSet

Store a value in Redis, returning the previously defined value.
redisHDel

Delete a hash value.
redisType

Query a Redis value type.
redisHGetAll

Redis hash fields and values.
redisDBSize

Return the number of keys in the current Redis database.
redisHIncrBy

Increment a value.
redisEval

Evaluate a Lua script in the Redis server.
redisHKeys

Redis hash fields.
redisLRange

Copy values from a list.
redisMove

Move the specified key/value pair to another database.
redisFlushDB

Delete all keys and values from the current database.
redisGetBit

Redis BITSET gets - get binary value
redisSUnionStore

Store the union of two or more sets.
redisHMSet

Store a list of hash values.
redisZAdd

redisZAdd
redisBLPop

Blocking List Pop
redisKeys

Return a list of all keys in the active Redis database.
redisSetContext

redisSetContext
redisBgSave

redisBgSave
redisSetPipeline

Set the Redis message blocking state.
redisLPush

Add a value to the head tail of a list.
redisCmd

General Redis Interface Function
redisBRPopLPush

Remove the tail from a list, blocking if it does not exist, pushing to another.
redisZRange

redisZRange
redisHMGet

Retrieve a list of hash values.
redisTTL

Return the time to live for a key set to expire.
redisMonitorChannels

redisMonitorChannels
redisWatch

redisWatch
redisSInter

Find and return the intersection of two or more sets.
redisSetBit

Redis BITSET - set binary value
redisInfo

redisInfo
redisRename

Rename a key.
redisSort

redisSort
redisUnwatch

redisUnwatch
redisZRemRangeByRank

redisZRemRangeByRank.Rd
redisShutdown

redisShutdown
redisZScore

redisZScore
redisClose

Close an open connection to a Redis server.
Increment, Decrement functions

Increment or decrement Redis values.
redisBitCount

Redis BITCOUNT - count all bits in key
redisConnect

Connect to a Redis server.
redisFlushAll

Delete all keys and values from all databases.
redisGetResponse

redisGetResponse
redisExpireAt

Set a timeout on the specified key.
redisHGet

Retrieve a hased value from Redis.
redisDiscard

redisDiscard
redisMGet

Retrieve one or more values from Redis.
redisGet

Retrieve a value from Redis.
redisSIsMember

Test for set membership
redisSave

redisSave
redisLIndex

Retrieve a value from a Redis 'list.'
redisMSet

Set one or more key/value pairs in the Redis database.
redisSRem

Remove an element from a set.
redisZUnionStore

redisZUnionStore
redisLRem

Remove elements from a list.
redisSMove

Move a set element.
redisRPopLPush

Remove the tail from a list, pushing to another.
redisSUnion

Return the union of two or more sets.
redisExists

Test the existence of a key in the Redis database.
redisSPop

Remove and return an element from a set.
redisHLen

Redis hash length.
redisSubscribe

redisSubscribe
redisHVals

Redis hash values.
redisSCard

Set cardinality
redisLPop

Remove the first element from a list.
redisUnsubscribe

redisUnsubscribe
redisZIncrBy

redisZIncrBy
redisZRank

redisZRank
redisLLen

Redis list length.
redisZInterStore

redisZInterStore
redisSDiff

Return the difference of two or more sets.
redisZCount

redisZCount
redisSInterStore

Store intersection of two or more sets.
redisSRandMember

Choose a random element from a set
redisSDiffStore

Store the difference of two or more sets.
redisZCard

redisZCard.Rd
redisZRangeByScore

redisZRangeByScore
rredis-package

Redis interface package.
redisExec

redisExec
redisHFields

Redis hash fields.
redisPersist

Clear expiration flags for a key
redisLTrim

Trim a list.
redisHSet

Store a hash value in Redis.
redisPublish

redisPublish
redisSAdd

Add an element to a set.
redisRandomKey

Return a randomly selected key from the currently selected database.
redisSelect

Select a redis database.
redisZRemRangeByScore

redisZRemRangeByScore.Rd
redisAuth

Redis authentication.
redisBgRewriteAOF

redisBgRewriteAOF
redisHExists

Test the existence of a hash.
redisLSet

Set a value within a list.
redisMulti

redisMulti
redisRPop

Remove the last element from a list.
redisSMembers

List elements of a set.
redisSlaveOf

redisSlaveOf
redisSet

Store a value in Redis.
redisBitOp

Redis BITOP - execute bitoperations on multiple bitsets
redisZRem

redisZRem