Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): all scan commands needs to return cursor as bulk string #503 #504

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)