5#define REDIS_RESULT_BUFFER_SIZE (10 * 1024)
87 LOGI(
"RedisBuffer:writeArray: %d", len);
90 for (
int i = 0; i < len; ++i) {
103 bool read(T& result)
override {
109 LOGI(
"RedisBuffer:read: no data available");
115 LOGI(
"Redis LPOP: %d", val);
130 while (read_count < len) {
146 bool peek(T& result)
override {
152 if (!resp.
ok)
return false;
165 LOGI(
"Redis DEL: %d", rc.intValue);
212 LOGI(
"RedisBuffer::resize: %d",
size);
223 operator bool()
const {
return ok; }
251 const String& arg2 =
"",
const String& arg3 =
"") {
253 String(1 + (arg1.length() > 0) + (arg2.length() > 0) +
254 (arg3.length() > 0)) +
256 out +=
"$" + String(cmd.length()) +
"\r\n" + cmd +
"\r\n";
258 out +=
"$" + String(arg1.length()) +
"\r\n" + arg1 +
"\r\n";
260 out +=
"$" + String(arg2.length()) +
"\r\n" + arg2 +
"\r\n";
262 out +=
"$" + String(arg3.length()) +
"\r\n" + arg3 +
"\r\n";
274 LOGE(
"Redis not connected");
301 String tail = (
char*)buffer;
302 int nl_pos = tail.indexOf(
"\r\n");
303 while (nl_pos >= 0) {
304 String head = tail.substring(0, nl_pos);
306 tail = tail.substring(nl_pos + 2);
308 nl_pos = tail.indexOf(
"\r\n");
311 if (!tail.startsWith(
"$") && tail.length() > 0) {
320 StrView line((
char*)buffer,
sizeof(buffer), n);
356 String cmd =
"*" + String(2 + write_size) +
"\r\n";
357 cmd +=
"$5\r\nRPUSH\r\n";
358 cmd +=
"$" + String(strlen(
key)) +
"\r\n" +
key +
"\r\n";
362 String sval = String(value);
363 cmd +=
"$" + String(sval.length()) +
"\r\n" + sval +
"\r\n";
367 LOGI(
"Redis RPUSH %d entries: %d (ok=%d)", write_size, resp.
intValue,
389 LOGE(
"Redis LPOP failed: %s", cmd.c_str());
392 for (
auto& str : rc.strValues) {
393 if (str.startsWith(
"*"))
continue;
394 if (str.startsWith(
"$"))
continue;
395 if (str.length() == 0)
continue;
396 LOGI(
"- %s", str.c_str());
397 T value = (T)str.toInt();
405 LOGW(
"RedisBuffer:fillReadBuffer: not enough data read from Redis");
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGE(...)
Definition AudioLoggerIDF.h:30
#define REDIS_RESULT_BUFFER_SIZE
Definition RedisBuffer.h:5
bool connected()
Definition Arduino.h:167
virtual int read(uint8_t *buffer, size_t len)
Definition Arduino.h:165
virtual void flush()
Definition Arduino.h:130
virtual int available()
Definition Arduino.h:139