Skip to content

Commit

Permalink
fix(server): all scan commands needs to return cursor as bulk string #…
Browse files Browse the repository at this point in the history
…503

Signed-off-by: Boaz Sade <[email protected]>
  • Loading branch information
boazsade committed Nov 21, 2022
1 parent 96c9332 commit 287ccdd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/server/generic_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ void GenericFamily::Scan(CmdArgList args, ConnectionContext* cntx) {
cursor = ScanGeneric(cursor, scan_op, &keys, cntx);

(*cntx)->StartArray(2);
(*cntx)->SendSimpleString(absl::StrCat(cursor));
(*cntx)->SendBulkString(absl::StrCat(cursor));
(*cntx)->StartArray(keys.size());
for (const auto& k : keys) {
(*cntx)->SendBulkString(k);
Expand Down
2 changes: 1 addition & 1 deletion src/server/hset_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ void HSetFamily::HScan(CmdArgList args, ConnectionContext* cntx) {
OpResult<StringVec> result = cntx->transaction->ScheduleSingleHopT(std::move(cb));
if (result.status() != OpStatus::WRONG_TYPE) {
(*cntx)->StartArray(2);
(*cntx)->SendSimpleString(absl::StrCat(cursor));
(*cntx)->SendBulkString(absl::StrCat(cursor));
(*cntx)->StartArray(result->size());
for (const auto& k : *result) {
(*cntx)->SendBulkString(k);
Expand Down
2 changes: 1 addition & 1 deletion src/server/set_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ void SScan(CmdArgList args, ConnectionContext* cntx) {
OpResult<StringVec> result = cntx->transaction->ScheduleSingleHopT(std::move(cb));
if (result.status() != OpStatus::WRONG_TYPE) {
(*cntx)->StartArray(2);
(*cntx)->SendSimpleString(absl::StrCat(cursor));
(*cntx)->SendBulkString(absl::StrCat(cursor));
(*cntx)->StartArray(result->size());
for (const auto& k : *result) {
(*cntx)->SendBulkString(k);
Expand Down
2 changes: 1 addition & 1 deletion src/server/zset_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ void ZSetFamily::ZScan(CmdArgList args, ConnectionContext* cntx) {
OpResult<StringVec> result = cntx->transaction->ScheduleSingleHopT(std::move(cb));
if (result.status() != OpStatus::WRONG_TYPE) {
(*cntx)->StartArray(2);
(*cntx)->SendSimpleString(absl::StrCat(cursor));
(*cntx)->SendBulkString(absl::StrCat(cursor));
(*cntx)->StartArray(result->size());
for (const auto& k : *result) {
(*cntx)->SendBulkString(k);
Expand Down
24 changes: 24 additions & 0 deletions tests/dragonfly/server_family_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import pytest
import redis
import random
from string import ascii_lowercase
import time
import datetime


def test_quit(connection):
Expand Down Expand Up @@ -60,3 +64,23 @@ def test_connection_name(client):
client.execute_command("CLIENT SETNAME test_conn_name")
name = client.execute_command("CLIENT GETNAME")
assert name == "test_conn_name"

'''
make sure that the scan command is working with python
'''
def test_scan(client):
def generate_key_val():
now = datetime.datetime.now()
for i in range(10):
string_val = "".join(random.choice(ascii_lowercase) for i in range(random.randint(1, 8)))
yield f"key{i}-{time.time()}", f"value={i}{string_val}{now}"
try:
for key, val in generate_key_val():
res = client.set(key, val)
assert res is not None
cur, keys = client.scan(cursor=0, match=key, count=2)
assert cur == 0
assert len(keys) == 1
assert keys[0] == key
except Exception as e:
assert False, str(e)

0 comments on commit 287ccdd

Please sign in to comment.