redis_client: Create a redis client

Description Usage Arguments Details Value See Also Examples

View source: R/client.R

Description

This functions return an object embedding Redis connection parameters. It can be propagated across all workers to share the same connect to the same redis database.

Usage

1

Arguments

type

type of client, see details

...

parameters to transmit to the client implementation (host, port, ...)

Details

RedisClient: Returns an instance of RedisClient class with methods allowing to manipulate 'Redis' database using a unified interface

As this package only needs a subset of 'Redis' commands are implemented. It's a very simple implementation to avoid extra dependency, limited to this package needs.

The returned "client" embeds connection configuration and can be propagated in distributed workers (like with 'foreach' package). So the client connection parameters are only to be defined once.

Clients:

rredis

rredis package, discontinued

rcpp

for RcppRedis

rredux

for redux and rrlite

mock

Mock type, in memory R-only client

The returned instance exposes the following functions :

connect()

connect to redis db

get(key)

get key value

hashGet(key, field)

get field value in HashSet named by key

hashSet(key, field, value)

set field value in HashSet named by key

hashSetCounter(key, field, value)

set field value for a counter in HashSet named by key

hashIncrBy(key, field, by)

Increment a field by the amount provided in by. Caution the field must have been initialized by hashSetCounter not by hashSet

delete(key)

remove the key key value

exists(key)

returns TRUE the key exists

pushTail(key, value)

add a value on the tail of the list named by key

hashGetAll(key)

returns all fields in the HashSet named by key. If not implemented client will not be usable for monitoring

Accepted parameters are

host

name of host

port

get key value

database

Redis database number

...

Some other parameters, not yet normalized across interfaces

Value

instance of a RedisClient class (described in details section)

See Also

Other backend: RedisClientMock-class, RedisClientRRedis-class, RedisClientRcpp-class, RedisClientRedux-class

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# Create a simple client using  rredis as backend
client = redis_client(host="127.0.0.1", type="rredis")

# Using another backend and database number 2
client = redis_client(host="127.0.0.1", type="redux", database=2)
## Not run: 
client$connect() # Initiate connection

## End(Not run)

client = redis_client("mock") # Mock client (in-memory only client)

client$connect()

client$exists("my-key") # Test if 'my-key' exists
client$set("my-key", 12) # Set a value
client$get("my-key")

client$hashSetCounter("a-key", "counter", 1) # Set a counter value in a hash field
client$hashIncrBy("a-key", "counter", 1) # Increment by 1

cturbelin/redisProgress documentation built on Dec. 10, 2019, 7:35 a.m.