Skip to content

Commit

Permalink
Merge branch 'unstable' into ft-tagvals-command
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanc-n authored Oct 3, 2024
2 parents a0d5f77 + 149d4fb commit 0a196b3
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cmake/jsoncons.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ include_guard()
include(cmake/utils.cmake)

FetchContent_DeclareGitHubWithMirror(jsoncons
danielaparker/jsoncons v0.176.0
MD5=5d0343fe48cbc640bdb42d89a5b87182
danielaparker/jsoncons v0.177.0
MD5=393062889321f4f715a9302d8f49acf8
)

FetchContent_MakeAvailableWithArgs(jsoncons
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,6 @@ REDIS_REGISTER_COMMANDS(Hash, MakeCmdAttr<CommandHGet>("hget", 3, "read-only", 1
MakeCmdAttr<CommandHGetAll>("hgetall", 2, "read-only slow", 1, 1, 1),
MakeCmdAttr<CommandHScan>("hscan", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandHRangeByLex>("hrangebylex", -4, "read-only", 1, 1, 1),
MakeCmdAttr<CommandHRandField>("hrandfield", -2, "read-only", 1, 1, 1), )
MakeCmdAttr<CommandHRandField>("hrandfield", -2, "read-only slow", 1, 1, 1), )

} // namespace redis
4 changes: 2 additions & 2 deletions src/commands/cmd_key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ REDIS_REGISTER_COMMANDS(Key, MakeCmdAttr<CommandTTL>("ttl", 2, "read-only", 1, 1
MakeCmdAttr<CommandRename>("rename", 3, "write", 1, 2, 1),
MakeCmdAttr<CommandRenameNX>("renamenx", 3, "write", 1, 2, 1),
MakeCmdAttr<CommandCopy>("copy", -3, "write", 1, 2, 1),
MakeCmdAttr<CommandSort<false>>("sort", -2, "write", 1, 1, 1),
MakeCmdAttr<CommandSort<true>>("sort_ro", -2, "read-only", 1, 1, 1))
MakeCmdAttr<CommandSort<false>>("sort", -2, "write slow", 1, 1, 1),
MakeCmdAttr<CommandSort<true>>("sort_ro", -2, "read-only slow", 1, 1, 1))

} // namespace redis
3 changes: 2 additions & 1 deletion src/commands/cmd_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ class CommandFTTagVals : public Commander {
};

REDIS_REGISTER_COMMANDS(Search,
MakeCmdAttr<CommandFTCreate>("ft.create", -2, "write exclusive no-multi no-script", 0, 0, 0),
MakeCmdAttr<CommandFTCreate>("ft.create", -2, "write exclusive no-multi no-script slow", 0, 0,
0),
MakeCmdAttr<CommandFTSearchSQL>("ft.searchsql", -2, "read-only", 0, 0, 0),
MakeCmdAttr<CommandFTSearch>("ft.search", -3, "read-only", 0, 0, 0),
MakeCmdAttr<CommandFTExplainSQL>("ft.explainsql", -2, "read-only", 0, 0, 0),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ REDIS_REGISTER_COMMANDS(Server, MakeCmdAttr<CommandAuth>("auth", 2, "read-only o
MakeCmdAttr<CommandRole>("role", 1, "read-only ok-loading", 0, 0, 0),
MakeCmdAttr<CommandConfig>("config", -2, "read-only", 0, 0, 0, GenerateConfigFlag),
MakeCmdAttr<CommandNamespace>("namespace", -3, "read-only", 0, 0, 0),
MakeCmdAttr<CommandKeys>("keys", 2, "read-only", 0, 0, 0),
MakeCmdAttr<CommandKeys>("keys", 2, "read-only slow", 0, 0, 0),
MakeCmdAttr<CommandFlushDB>("flushdb", 1, "write no-dbsize-check", 0, 0, 0),
MakeCmdAttr<CommandFlushAll>("flushall", 1, "write no-dbsize-check", 0, 0, 0),
MakeCmdAttr<CommandDBSize>("dbsize", -1, "read-only", 0, 0, 0),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ REDIS_REGISTER_COMMANDS(Set, MakeCmdAttr<CommandSAdd>("sadd", -3, "write", 1, 1,
MakeCmdAttr<CommandSIsMember>("sismember", 3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandSMIsMember>("smismember", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandSPop>("spop", -2, "write", 1, 1, 1),
MakeCmdAttr<CommandSRandMember>("srandmember", -2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandSRandMember>("srandmember", -2, "read-only slow", 1, 1, 1),
MakeCmdAttr<CommandSMove>("smove", 4, "write", 1, 2, 1),
MakeCmdAttr<CommandSDiff>("sdiff", -2, "read-only slow", 1, -1, 1),
MakeCmdAttr<CommandSUnion>("sunion", -2, "read-only slow", 1, -1, 1),
Expand Down
14 changes: 12 additions & 2 deletions src/commands/cmd_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1537,15 +1537,25 @@ class CommandXReadGroup : public Commander,

if (block_ && results.empty()) {
if (conn->IsInExec()) {
*output = redis::MultiLen(-1);
output->append(redis::MultiLen(streams_.size()));
for (const auto &stream_name : streams_) {
output->append(redis::MultiLen(2));
output->append(redis::BulkString(stream_name));
output->append(redis::MultiLen(0));
}
return Status::OK(); // No blocking in multi-exec
}

return BlockingRead(srv, conn, &stream_db);
}

if (!block_ && results.empty()) {
*output = redis::MultiLen(-1);
output->append(redis::MultiLen(streams_.size()));
for (const auto &stream_name : streams_) {
output->append(redis::MultiLen(2));
output->append(redis::BulkString(stream_name));
output->append(redis::MultiLen(0));
}
return Status::OK();
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_txn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class CommandUnwatch : public Commander {

REDIS_REGISTER_COMMANDS(Txn, MakeCmdAttr<CommandMulti>("multi", 1, "multi", 0, 0, 0),
MakeCmdAttr<CommandDiscard>("discard", 1, "multi", 0, 0, 0),
MakeCmdAttr<CommandExec>("exec", 1, "exclusive multi", 0, 0, 0),
MakeCmdAttr<CommandExec>("exec", 1, "exclusive multi slow", 0, 0, 0),
MakeCmdAttr<CommandWatch>("watch", -2, "multi", 1, -1, 1),
MakeCmdAttr<CommandUnwatch>("unwatch", 1, "multi", 0, 0, 0), )

Expand Down
16 changes: 9 additions & 7 deletions src/types/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ struct JsonValue {
Mul = 2,
};

static const size_t default_max_nesting_depth = 1024;

JsonValue() = default;
explicit JsonValue(jsoncons::basic_json<char> value) : value(std::move(value)) {}

static StatusOr<JsonValue> FromString(std::string_view str, int max_nesting_depth = std::numeric_limits<int>::max()) {
static StatusOr<JsonValue> FromString(std::string_view str, int max_nesting_depth = default_max_nesting_depth) {
jsoncons::json val;

jsoncons::json_options options;
Expand All @@ -69,7 +71,7 @@ struct JsonValue {
return JsonValue(std::move(val));
}

static StatusOr<JsonValue> FromCBOR(std::string_view str, int max_nesting_depth = std::numeric_limits<int>::max()) {
static StatusOr<JsonValue> FromCBOR(std::string_view str, int max_nesting_depth = default_max_nesting_depth) {
jsoncons::json val;

jsoncons::cbor::cbor_options options;
Expand All @@ -84,13 +86,13 @@ struct JsonValue {
return JsonValue(std::move(val));
}

StatusOr<std::string> Dump(int max_nesting_depth = std::numeric_limits<int>::max()) const {
StatusOr<std::string> Dump(int max_nesting_depth = default_max_nesting_depth) const {
std::string res;
GET_OR_RET(Dump(&res, max_nesting_depth));
return res;
}

Status Dump(std::string *buffer, int max_nesting_depth = std::numeric_limits<int>::max()) const {
Status Dump(std::string *buffer, int max_nesting_depth = default_max_nesting_depth) const {
jsoncons::json_options options;
options.max_nesting_depth(max_nesting_depth);

Expand All @@ -104,13 +106,13 @@ struct JsonValue {
return Status::OK();
}

StatusOr<std::string> DumpCBOR(int max_nesting_depth = std::numeric_limits<int>::max()) const {
StatusOr<std::string> DumpCBOR(int max_nesting_depth = default_max_nesting_depth) const {
std::string res;
GET_OR_RET(DumpCBOR(&res, max_nesting_depth));
return res;
}

Status DumpCBOR(std::string *buffer, int max_nesting_depth = std::numeric_limits<int>::max()) const {
Status DumpCBOR(std::string *buffer, int max_nesting_depth = default_max_nesting_depth) const {
jsoncons::cbor::cbor_options options;
options.max_nesting_depth(max_nesting_depth);

Expand Down Expand Up @@ -221,7 +223,7 @@ struct JsonValue {
}

StatusOr<std::vector<size_t>> GetBytes(std::string_view path, JsonStorageFormat format,
int max_nesting_depth = std::numeric_limits<int>::max()) const {
int max_nesting_depth = default_max_nesting_depth) const {
std::vector<size_t> results;
Status s;
try {
Expand Down
30 changes: 30 additions & 0 deletions tests/gocase/unit/type/stream/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,36 @@ func TestStreamOffset(t *testing.T) {
require.Equal(t, int64(0), ri[0].Pending)
})

t.Run("XREADGROUP with empty streams returns empty arrays", func(t *testing.T) {
streamName := "test-stream-empty1"
streamName2 := "test-stream-empty2"
groupName := "test-group-empty"
consumerName := "test-consumer-empty"

require.NoError(t, rdb.XGroupCreateMkStream(ctx, streamName, groupName, "0").Err())
require.NoError(t, rdb.XGroupCreateMkStream(ctx, streamName2, groupName, "0").Err())

res, err := rdb.XReadGroup(ctx, &redis.XReadGroupArgs{
Group: groupName,
Consumer: consumerName,
Streams: []string{streamName, streamName2, "0", "0"},
}).Result()
require.NoError(t, err)

expectedRes := []redis.XStream{
{
Stream: streamName,
Messages: []redis.XMessage{},
},
{
Stream: streamName2,
Messages: []redis.XMessage{},
},
}

require.Equal(t, expectedRes, res)
})

t.Run("XGROUP SETID with different kinds of commands", func(t *testing.T) {
streamName := "test-stream"
groupName := "test-group"
Expand Down

0 comments on commit 0a196b3

Please sign in to comment.