8 data = client.readStringUntil(
'\r');
14 String emitStr((
char)
_type);
25 auto dLen =
data.toInt();
30 data = (
const char *)
nullptr;
34 auto charBuf =
new char[dLen + 1];
35 bzero(charBuf, dLen + 1);
37 auto readB = client.readBytes(charBuf, dLen);
38 if ((
int)readB != dLen)
40 Serial.printf(
"ERROR! Bad read (%ld ?= %ld)\n", (
long)readB, (
long)dLen);
44 data = String(charBuf);
50 String emitStr((
char)
_type);
51 emitStr += String(
data.length());
60 for (
int i = 0; i <
data.toInt(); i++)
64 RedisArray::operator std::vector<std::shared_ptr<RedisObject>>()
const
69 RedisArray::operator std::vector<String>()
const
71 std::vector<String> rv;
74 if (ro->type() == RedisObject::Type::Array)
76 for (
auto append_inner :
dynamic_cast<RedisArray*
>(ro.get())->operator std::vector<String>())
78 rv.push_back(append_inner);
83 rv.push_back((String)*ro.get());
91 String emitStr((
char)
_type);
92 emitStr += String(
vec.size());
94 for (
auto rTypeInst :
vec)
96 emitStr += rTypeInst->RESP();
103 if (!cmdClient.connected())
106 auto cmdRespStr =
RESP();
107 cmdClient.print(cmdRespStr);
109 if (ret && ret->type() == RedisObject::Type::InternalError)
115 int RedisCommand::issue_typed<int>(Client &cmdClient)
117 auto cmdRet =
issue(cmdClient);
119 return INT_MAX - 0x0f;
120 if (cmdRet->type() != RedisObject::Type::Integer)
121 return INT_MAX - 0xf0;
126 bool RedisCommand::issue_typed<bool>(Client &cmdClient)
128 auto cmdRet =
issue(cmdClient);
129 if (cmdRet && cmdRet->type() == RedisObject::Type::Integer)
135 String RedisCommand::issue_typed<String>(Client &cmdClient)
137 return (String)*
issue(cmdClient);
143 {RedisObject::Type::SimpleString, [](Client &c)
145 {RedisObject::Type::BulkString, [](Client &c)
147 {RedisObject::Type::Integer, [](Client &c)
149 {RedisObject::Type::Array, [](Client &c)
151 {RedisObject::Type::Error, [](Client &c)
156 if (client.connected() && !client.available()) {
161 if (!client.connected())
167 if (typeChar == -1 || typeChar ==
'\r' || typeChar ==
'\n') {
171 if (g_TypeParseMap.find(typeChar) != g_TypeParseMap.end())
173 auto retVal = g_TypeParseMap[typeChar](client);
180 return std::shared_ptr<RedisObject>(retVal);
188 std::shared_ptr<RedisObject>
type =
nullptr;
189 while (
type==
nullptr) {