Skip to content

Commit

Permalink
fix(server): scan cursor returning bulk string #503
Browse files Browse the repository at this point in the history
Signed-off-by: Boaz Sade <[email protected]>
  • Loading branch information
boazsade committed Nov 21, 2022
1 parent 96c9332 commit 2b5f33a
Show file tree
Hide file tree
Showing 5 changed files with 24 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
20 changes: 20 additions & 0 deletions tests/dragonfly/server_family_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import pytest
import redis
import random
from string import ascii_lowercase
import time
import datetime
from .utility import *


def test_quit(connection):
Expand Down Expand Up @@ -60,3 +65,18 @@ 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):
try:
for key, val in gen_test_data(n=10, seed="set-test-key"):
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 2b5f33a

Please sign in to comment.