A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/openresty/lua-redis-parser/commit/32cee57a5ac9dc90d04c581678cf6c85fec39693 below:

nil multi bulk replies did not parse at all. thanks 郭颖. · openresty/lua-redis-parser@32cee57 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+90

-2

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+90

-2

lines changed Original file line number Diff line number Diff line change

@@ -36,7 +36,7 @@ static const char *redis_typenames[] = {

36 36 37 37

#define UINT64_LEN (sizeof("18446744073709551615") - 1)

38 38 39 -

static char *redis_null = "null";

39 +

static void *redis_null = NULL;

40 40 41 41

static int parse_reply_helper(lua_State *L, char **src, size_t len);

42 42

static int redis_parse_reply(lua_State *L);

@@ -248,6 +248,7 @@ parse_reply_helper(lua_State *L, char **src, size_t len)

248 248

if (dst_len == -1) {

249 249

*src = (char *) dst + sizeof("\r\n") - 1;

250 250 251 +

/* lua_pushlightuserdata(L, redis_null); */

251 252

lua_pushnil(L);

252 253

lua_pushnumber(L, BULK_REPLY);

253 254

return 2;

@@ -420,6 +421,24 @@ parse_multi_bulk_reply(lua_State *L, char **src, const char *last)

420 421

CHECK_EOF

421 422 422 423

while (*p != '\r') {

424 +

if (*p == '-') {

425 + 426 +

p++;

427 +

CHECK_EOF

428 + 429 +

if (*p < '0' || *p > '9') {

430 +

goto invalid;

431 +

}

432 + 433 +

while (*p != '\r') {

434 +

p++;

435 +

CHECK_EOF

436 +

}

437 + 438 +

count = -1;

439 +

break;

440 +

}

441 + 423 442

if (*p < '0' || *p > '9') {

424 443

dd("expecting digit, but found %c", *p);

425 444

goto invalid;

@@ -445,6 +464,15 @@ parse_multi_bulk_reply(lua_State *L, char **src, const char *last)

445 464 446 465

dd("reading the individual bulks");

447 466 467 +

if (count == -1) {

468 + 469 +

/* lua_pushlightuserdata(L, redis_null); */

470 +

lua_pushnil(L);

471 + 472 +

*src = (char *) p;

473 +

return PARSE_OK;

474 +

}

475 + 448 476

lua_createtable(L, count, 0);

449 477 450 478

for (i = 1; i <= count; i++) {

Original file line number Diff line number Diff line change

@@ -255,3 +255,33 @@ res[1][2] == 5 == 5

255 255

res[2][1] == ["a"]

256 256

res[2][2] == 5 == 5

257 257 258 + 259 + 260 +

=== TEST 10: nil multi bulk reply and status reply

261 +

--- lua

262 +

parser = require("redis.parser")

263 +

replies = '*-1\r\n+DONE\r\n'

264 +

results = parser.parse_replies(replies, 2)

265 +

print("res count == " .. #results)

266 +

print("res[1] count == " .. #results[1])

267 +

print("res[2] count == " .. #results[2])

268 + 269 +

local res = results[1]

270 + 271 +

print("res[1][1] == " .. (res[1] or "nil"))

272 +

print("res[1][2] == " .. res[2] .. ' == ' .. parser.MULTI_BULK_REPLY)

273 + 274 +

res = results[2]

275 + 276 +

print("res[2][1] == " .. res[1])

277 +

print("res[2][2] == " .. res[2] .. ' == ' .. parser.STATUS_REPLY)

278 + 279 +

--- out

280 +

res count == 2

281 +

res[1] count == 2

282 +

res[2] count == 2

283 +

res[1][1] == nil

284 +

res[1][2] == 5 == 5

285 +

res[2][1] == DONE

286 +

res[2][2] == 1 == 1

287 + Original file line number Diff line number Diff line change

@@ -272,9 +272,11 @@ reply = '*4\r\n$1\r\na\r\n$-1\r\n$0\r\n\r\n$5\r\nhello\r\n'

272 272

res, typ = parser.parse_reply(reply)

273 273

print("typ == " .. typ .. ' == ' .. parser.MULTI_BULK_REPLY)

274 274

print("res == " .. cjson.encode(res))

275 +

print("res[2]:", res[2]);

275 276

--- out eval

276 277

qq{typ == 5 == 5

277 -

res == ["a",null,"","hello"]\n}

278 +

res == ["a",null,"","hello"]

279 +

res[2]:\tnil\n}

278 280 279 281 280 282

@@ -467,3 +469,31 @@ print(parser.typename(6))

467 469

nil

468 470

nil

469 471 472 + 473 + 474 +

=== TEST 36: empty multi bulk reply (0 bulk)

475 +

--- lua

476 +

cjson = require('cjson')

477 +

parser = require("redis.parser")

478 +

reply = '*0\r\n'

479 +

res, typ = parser.parse_reply(reply)

480 +

print("typ == " .. typ .. ' == ' .. parser.typename(typ) .. ' == ' .. parser.MULTI_BULK_REPLY)

481 +

print("res == " .. cjson.encode(res))

482 +

--- out eval

483 +

qq{typ == 5 == multi-bulk reply == 5

484 +

res == \{\}\n}

485 + 486 + 487 + 488 +

=== TEST 37: nil multi bulk reply (-1 bulk)

489 +

--- lua

490 +

cjson = require('cjson')

491 +

parser = require("redis.parser")

492 +

reply = '*-1\r\n'

493 +

res, typ = parser.parse_reply(reply)

494 +

print("typ == " .. typ .. ' == ' .. parser.typename(typ) .. ' == ' .. parser.MULTI_BULK_REPLY)

495 +

print("res == " .. cjson.encode(res))

496 +

--- out eval

497 +

qq{typ == 5 == multi-bulk reply == 5

498 +

res == null\n}

499 +

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4