2#include "AudioTools/CoreAudio/Buffers.h"
4#define REDIS_RESULT_BUFFER_SIZE (10 * 1024)
83 LOGI(
"RedisBuffer:writeArray: %d", len);
86 for (
int i = 0; i < len; ++i) {
99 bool read(T& result)
override {
105 LOGI(
"RedisBuffer:read: no data available");
111 LOGI(
"Redis LPOP: %d", val);
99 bool read(T& result)
override {
…}
126 while (read_count < len) {
142 bool peek(T& result)
override {
148 if (!resp.
ok)
return false;
161 LOGI(
"Redis DEL: %d", rc.intValue);
175 LOGI(
"LLEN: %d (ok=%d)", resp.
intValue, resp.
ok);
208 LOGI(
"RedisBuffer::resize: %d",
size);
219 operator bool()
const {
return ok; }
232 void clearResponse() {
233 while (
client.available()) {
247 const String& arg2 =
"",
const String& arg3 =
"") {
249 String(1 + (arg1.length() > 0) + (arg2.length() > 0) +
250 (arg3.length() > 0)) +
252 out +=
"$" + String(cmd.length()) +
"\r\n" + cmd +
"\r\n";
254 out +=
"$" + String(arg1.length()) +
"\r\n" + arg1 +
"\r\n";
256 out +=
"$" + String(arg2.length()) +
"\r\n" + arg2 +
"\r\n";
258 out +=
"$" + String(arg3.length()) +
"\r\n" + arg3 +
"\r\n";
269 if (!
client.connected()) {
270 LOGE(
"Redis not connected");
288 uint8_t buffer[REDIS_RESULT_BUFFER_SIZE] = {};
291 n =
client.read(buffer,
sizeof(buffer));
297 String tail = (
char*)buffer;
298 int nl_pos = tail.indexOf(
"\r\n");
299 while (nl_pos >= 0) {
300 String head = tail.substring(0, nl_pos);
301 if (!head.startsWith(
"$"))
303 tail = tail.substring(nl_pos + 2);
305 nl_pos = tail.indexOf(
"\r\n");
308 if (!tail.startsWith(
"$") && tail.length() > 0) {
317 StrView line((
char*)buffer,
sizeof(buffer), n);
354 String cmd =
"*" + String(2 + write_size) +
"\r\n";
355 cmd +=
"$5\r\nRPUSH\r\n";
356 cmd +=
"$" + String(strlen(
key)) +
"\r\n" +
key +
"\r\n";
360 String sval = String(value);
361 cmd +=
"$" + String(sval.length()) +
"\r\n" + sval +
"\r\n";
365 LOGI(
"Redis RPUSH %d entries: %d (ok=%d)", write_size, resp.
intValue,
371 LOGI(
"Redis EXPIRE: %d (ok=%d)", resp.
intValue, resp.
ok);
382 LOGI(
"Redis LPOP: %d",
size)
387 LOGE(
"Redis LPOP failed: %s", cmd.c_str());
390 for (
auto& str : rc.strValues) {
391 if (str.startsWith(
"*"))
continue;
392 if (str.startsWith(
"$"))
continue;
393 if (str.length() == 0)
continue;
394 LOGI(
"- %s", str.c_str());
395 T value = (T)str.toInt();
399 LOGI(
"RedisBuffer: %d of %d items",(
int)
read_buf.available(),(
int)
read_buf.size() );
402 LOGW(
"RedisBuffer:fillReadBuffer: not enough data read from Redis");