Arduino-Redis
A Redis library for Arduino.
Public Member Functions | List of all members
Redis Class Reference

Detailed Description

Redis-for-Arduino client interface.

The sole constructor takes a reference to any instance of a Client subclass, allowing it to be used with any library that abstracts the client bytestream in this way (such as the built-in Ethernet class or the WiFiClient for devices such as the ESP8266).

Definition at line 43 of file Redis.h.

Public Member Functions

 Redis (Client &client)
 
 Redis (const Redis &)=delete
 
Redisoperator= (const Redis &)=delete
 
RedisReturnValue authenticate (const char *password)
 
bool set (const char *key, const char *value)
 
String get (const char *key)
 
bool del (const char *key)
 
bool exists (const char *key)
 
int append (const char *key, const char *value)
 
int publish (const char *channel, const char *message)
 
bool expire (const char *key, int seconds)
 
bool expire_at (const char *key, int timestamp)
 
bool pexpire (const char *key, int ms)
 
bool pexpire_at (const char *key, int timestamp)
 
bool persist (const char *key)
 
int ttl (const char *key)
 
int pttl (const char *key)
 
bool hset (const char *key, const char *field, const char *value)
 
bool hsetnx (const char *key, const char *field, const char *value)
 
String hget (const char *key, const char *field)
 
bool hdel (const char *key, const char *field)
 
int hlen (const char *key)
 
int hstrlen (const char *key, const char *field)
 
bool hexists (const char *key, const char *field)
 
std::vector< String > lrange (const char *key, int start, int stop)
 

#include <Redis.h>

Constructor & Destructor Documentation

◆ Redis()

Redis::Redis ( Client &  client)
inline

Create a Redis connection using Client reference client.

Parameters
clientA Client instance representing the connection to a Redis server.
Returns
An initialized Redis client using client to communicate with the server.

Definition at line 50 of file Redis.h.

Member Function Documentation

◆ append()

int Redis::append ( const char *  key,
const char *  value 
)

Appends value to key.

Parameters
key
value
Returns
The length of the string after the append operation.

Definition at line 41 of file Redis.cpp.

◆ authenticate()

RedisReturnValue Redis::authenticate ( const char *  password)

Authenticate with the given password.

Parameters
passwordThe password with which to authenticate.
Returns
RedisReturnValue detailing the result

Definition at line 6 of file Redis.cpp.

◆ del()

bool Redis::del ( const char *  key)

Delete key.

Parameters
key
Returns
true if key was removed.

Definition at line 36 of file Redis.cpp.

◆ exists()

bool Redis::exists ( const char *  key)

Determine if key exists.

Parameters
key
Returns
true if key exists.

Definition at line 51 of file Redis.cpp.

◆ expire()

bool Redis::expire ( const char *  key,
int  seconds 
)
inline

Expire a key in seconds.

Parameters
keyThe key name for which to set expire time.
secondsThe number of seconds (from "now") at which this key will expire.
Returns
true if the expire time was set successfully, false otherwise.

Definition at line 117 of file Redis.h.

◆ expire_at()

bool Redis::expire_at ( const char *  key,
int  timestamp 
)
inline

Expire a key at UNIX timestamp timestamp (seconds since January 1, 1970).

Note
A timestamp in the past will delete the key immediately.
Parameters
keyThe key name for which to set expire time.
timestampThe UNIX timestamp at which this key will expire.
Returns
true if the expire time was set successfully, false otherwise.

Definition at line 126 of file Redis.h.

◆ get()

String Redis::get ( const char *  key)

Get key.

Parameters
keyThe key name to retrieve.
Returns
The key`s value as a string, null if the key does not exist.

Definition at line 31 of file Redis.cpp.

◆ hdel()

bool Redis::hdel ( const char *  key,
const char *  field 
)

Delete the field stored in hash at key.

Parameters
key
field
Returns
true if deleted

Definition at line 81 of file Redis.cpp.

◆ hexists()

bool Redis::hexists ( const char *  key,
const char *  field 
)

Determine if field exists in hash at key.

Parameters
key
field
Returns
true if key exists.

Definition at line 96 of file Redis.cpp.

◆ hget()

String Redis::hget ( const char *  key,
const char *  field 
)

Gets field stored in hash at key.

Parameters
key
field
Returns
The field`s value.

Definition at line 76 of file Redis.cpp.

◆ hlen()

int Redis::hlen ( const char *  key)

Gets the number of fields stored in hash at key.

Parameters
key
Returns
The number of fields.

Definition at line 86 of file Redis.cpp.

◆ hset()

bool Redis::hset ( const char *  key,
const char *  field,
const char *  value 
)
inline

Set field in hash at key to value.

Parameters
key
field
value
Returns
true if set, false if was updated

Definition at line 175 of file Redis.h.

◆ hsetnx()

bool Redis::hsetnx ( const char *  key,
const char *  field,
const char *  value 
)
inline

Set field in hash at key to value i.f.f. field does not yet exist.

Parameters
key
field
value
Returns
true if set, false if field already existed

Definition at line 184 of file Redis.h.

◆ hstrlen()

int Redis::hstrlen ( const char *  key,
const char *  field 
)

Gets the length of the string at field in hash named key.

Parameters
key
field
Returns
The field's string length value.

Definition at line 91 of file Redis.cpp.

◆ lrange()

std::vector< String > Redis::lrange ( const char *  key,
int  start,
int  stop 
)

Returns the specified elements of the list stored at key.

Parameters
startZero-based starting index (can be negative to indicate end-of-list offset).
endZero-based ending index.
Returns
The list of elements, as a vector of Strings; or an empty vector if error/DNE.

Definition at line 101 of file Redis.cpp.

◆ persist()

bool Redis::persist ( const char *  key)

Persist key (remove any expiry).

Parameters
keyThe key to persist.
Returns
true if the timeout was removed, false if key DNE or had no expiry.

Definition at line 61 of file Redis.cpp.

◆ pexpire()

bool Redis::pexpire ( const char *  key,
int  ms 
)
inline

Expire a key in milliseconds.

Parameters
keyThe key name for which to set expire time.
millisecondsThe number of milliseconds (from "now") at which this key will expire.
Returns
true if the expire time was set successfully, false otherwise.

Definition at line 134 of file Redis.h.

◆ pexpire_at()

bool Redis::pexpire_at ( const char *  key,
int  timestamp 
)
inline

Expire a key at UNIX timestamp timestamp (milliseconds since January 1, 1970).

Note
A timestamp in the past will delete the key immediately.
Parameters
keyThe key name for which to set expire time.
timestampThe UNIX timestamp at which this key will expire.
Returns
true if the expire time was set successfully, false otherwise.

Definition at line 143 of file Redis.h.

◆ pttl()

int Redis::pttl ( const char *  key)
inline

Query remaining time-to-live (time-until-expiry) for key.

Parameters
keyThe query whose TTL to query.
Returns
The key`s TTL in milliseconds, or a negative value signaling error: -1 if the key exists but has no associated expire, -2 if the key DNE.

Definition at line 166 of file Redis.h.

◆ publish()

int Redis::publish ( const char *  channel,
const char *  message 
)

Publish message to channel.

Parameters
channelThe channel on which to publish the message.
messageThe message to be published to the channel.
Returns
The number of subscribers to the published message.

Definition at line 46 of file Redis.cpp.

◆ set()

bool Redis::set ( const char *  key,
const char *  value 
)

Set key to value.

Note
Current implementation only supports basic SET without behavioral modification options added in Redis 2.6.12. To expire a set key, use the expire() method below.
Parameters
keyThe key name to set
valueThe value to set for key
Returns
true if key was set to value, false if error.

Definition at line 24 of file Redis.cpp.

◆ ttl()

int Redis::ttl ( const char *  key)
inline

Query remaining time-to-live (time-until-expiry) for key.

Parameters
keyThe query whose TTL to query.
Returns
The key's TTL in seconds, or a negative value signaling error: -1 if the key exists but has no associated expire, -2 if the key DNE.

Definition at line 158 of file Redis.h.