arduino-audio-tools
|
Buffer implementation that stores and retrieves data from a Redis server using the Arduino Client. More...
#include <RedisBuffer.h>
Classes | |
struct | RedisResult |
Public Member Functions | |
RedisBuffer (Client &client, const char *key, size_t max_size, size_t local_buf_size=512, int expire_seconds=60 *60) | |
Constructs a RedisBuffer. | |
T * | address () override |
Returns the address of the start of the physical read buffer (not supported). | |
int | available () override |
Returns the number of elements available to read (local + Redis). Flushes any pending writes before checking. | |
int | availableForWrite () override |
Returns the number of elements that can be written before reaching max_size. There are are no checks in place that would prevent that the size values is exeeded: This is for information only! | |
void | clear () |
same as reset | |
virtual int | clearArray (int len) |
Removes the next len entries. | |
bool | isEmpty () |
virtual bool | isFull () |
checks if the buffer is full | |
virtual float | levelPercent () |
Returns the level of the buffer in %. | |
bool | peek (T &result) override |
Peeks at the next value in Redis directly (no local buffer). Flushes any pending writes before peeking. | |
bool | read (T &result) override |
Reads a single value from Redis directly (no local buffer). Flushes any pending writes before reading. | |
int | readArray (T data[], int len) override |
Reads multiple values from the buffer in one batch. Flushes any pending writes before reading. | |
void | reset () override |
Clears the buffer both locally and on the Redis server. Flushes any pending writes before clearing. | |
bool | resize (int size) override |
Resizes the maximum buffer size. This operation is only allowed before any write has occurred. | |
void | setExpire (int seconds) |
Sets the expiration time (in seconds) for the Redis key. The expiration will be refreshed on every write/flush. | |
size_t | size () override |
Returns the maximum capacity of the buffer. | |
bool | write (T data) override |
Buffers a single value for writing to Redis. Data is only sent to Redis when the local buffer is full or writeArray is called. | |
int | writeArray (const T data[], int len) override |
Writes multiple values to Redis in one batch. Flushes any pending writes before sending the new data. | |
virtual int | writeArrayOverwrite (const T data[], int len) |
Fills the buffer data and overwrites the oldest data if the buffer is full. | |
Protected Member Functions | |
void | clearResponse () |
void | fillReadBuffer () |
Fills the local read buffer from Redis using LRANGE. After reading, removes the items from Redis using LTRIM. | |
void | flushWrite () |
Flushes buffered writes to Redis using RPUSH and sets expiration if configured. | |
RedisResult | readResponse () |
Reads a single line response from the Redis server and parses it into a RedisResult. | |
String | redisCommand (const String &cmd, const String &arg1="", const String &arg2="", const String &arg3="") |
Constructs a Redis command in RESP format. | |
RedisResult | sendCommand (const String &cmd) |
Sends a command to the Redis server and returns the parsed result. | |
Protected Attributes | |
Client & | client |
Reference to the Arduino Client for Redis communication. | |
int | expire_seconds = 0 |
Expiration time in seconds (0 = no expiration). | |
bool | has_written = false |
True if any write operation has occurred. | |
const char * | key |
Redis key for the buffer. | |
size_t | local_buf_size |
Local buffer size for batching. | |
size_t | max_size |
Maximum number of elements in the buffer. | |
SingleBuffer< T > | read_buf |
Local buffer for pending reads. | |
SingleBuffer< T > | write_buf |
Local buffer for pending writes. | |
Buffer implementation that stores and retrieves data from a Redis server using the Arduino Client.
This buffer uses a Redis list as a circular buffer and batches read/write operations for efficiency. Individual write/read calls are buffered locally using SingleBuffer and only sent to Redis in bulk when writeArray/readArray is called or when the buffer is full/empty. This reduces network overhead and improves performance for streaming scenarios.
T | Data type to buffer (e.g., uint8_t, int16_t) |
|
inline |
Constructs a RedisBuffer.
client | Reference to a connected Arduino Client (e.g., WiFiClient, EthernetClient). |
key | Redis key to use for the buffer (list). |
max_size | Maximum number of elements in the buffer. |
local_buf_size | Size of the local buffer for batching (default: 512). |
expire_seconds | Number of seconds after which the Redis key should expire (0 = no expiration). |
|
inlineoverridevirtual |
Returns the address of the start of the physical read buffer (not supported).
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
Returns the number of elements available to read (local + Redis). Flushes any pending writes before checking.
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
Returns the number of elements that can be written before reaching max_size. There are are no checks in place that would prevent that the size values is exeeded: This is for information only!
Implements BaseBuffer< T >.
|
inlinevirtualinherited |
Removes the next len entries.
Reimplemented in SingleBuffer< T >, SingleBuffer< float >, SingleBuffer< int16_t >, SingleBuffer< stsz_sample_size_t >, SingleBuffer< uint32_t >, and SingleBuffer< uint8_t >.
|
inlinevirtualinherited |
checks if the buffer is full
Reimplemented in VariableSpeedRingBufferSimple< T >, VariableSpeedRingBuffer180< T >, VariableSpeedRingBuffer< T >, VariableSpeedRingBuffer< int16_t >, NBuffer< T >, NBuffer< Frame >, NBuffer< uint8_t >, BufferRP2040T< T >, BufferRTOS< T >, BufferRTOS< uint8_t >, SynchronizedBuffer< T >, SingleBuffer< T >, SingleBuffer< float >, SingleBuffer< int16_t >, SingleBuffer< stsz_sample_size_t >, SingleBuffer< uint32_t >, SingleBuffer< uint8_t >, RingBuffer< T >, RingBuffer< int16_t >, RingBuffer< Sample >, RingBuffer< uint16_t >, RingBuffer< uint8_t >, RingBufferFile< File, T >, and DynamicMultiBuffer< T, BufferType >.
|
inlineoverridevirtual |
Peeks at the next value in Redis directly (no local buffer). Flushes any pending writes before peeking.
result | Reference to store the peeked value. |
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
Reads a single value from Redis directly (no local buffer). Flushes any pending writes before reading.
result | Reference to store the read value. |
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
Reads multiple values from the buffer in one batch. Flushes any pending writes before reading.
data | Array to store the read values. |
len | Maximum number of values to read. |
Reimplemented from BaseBuffer< T >.
|
inlineprotected |
Reads a single line response from the Redis server and parses it into a RedisResult.
this is a length prefix line
Remove any leading or trailing whitespace
|
inlineprotected |
Constructs a Redis command in RESP format.
cmd | Redis command (e.g., "RPUSH"). |
arg1 | First argument. |
arg2 | Second argument. |
arg3 | Third argument. |
|
inlineoverridevirtual |
Clears the buffer both locally and on the Redis server. Flushes any pending writes before clearing.
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
Resizes the maximum buffer size. This operation is only allowed before any write has occurred.
size | New maximum size. |
Reimplemented from BaseBuffer< T >.
|
inlineprotected |
Sends a command to the Redis server and returns the parsed result.
cmd | Command string in RESP format. |
|
inline |
Sets the expiration time (in seconds) for the Redis key. The expiration will be refreshed on every write/flush.
seconds | Expiration time in seconds (0 = no expiration). |
|
inlineoverridevirtual |
Returns the maximum capacity of the buffer.
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
Buffers a single value for writing to Redis. Data is only sent to Redis when the local buffer is full or writeArray is called.
data | Value to write. |
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
Writes multiple values to Redis in one batch. Flushes any pending writes before sending the new data.
data | Array of values to write. |
len | Number of values to write. |
Reimplemented from BaseBuffer< T >.