Skip to content

Commit b91e549

Browse files
authored
Rebranding module to use Valkey instead of Redis (#194)
* Rebranding module to use Valkey instead of Redis fixes: #5 Signed-off-by: Yana Molodetsky <[email protected]>
1 parent 08b14a7 commit b91e549

File tree

162 files changed

+5009
-8390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+5009
-8390
lines changed

src/acl.cc

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ bool IsAllowedCommands(
211211
return allowed;
212212
}
213213

214-
absl::string_view CallReplyStringToStringView(RedisModuleCallReply *r) {
214+
absl::string_view CallReplyStringToStringView(ValkeyModuleCallReply *r) {
215215
size_t l;
216-
const char *r_c_str = RedisModule_CallReplyStringPtr(r, &l);
216+
const char *r_c_str = ValkeyModule_CallReplyStringPtr(r, &l);
217217
return {r_c_str, l};
218218
}
219219

@@ -278,18 +278,18 @@ bool IsPrefixAllowed(const absl::string_view &module_prefix,
278278

279279
void GetAclViewFromCallReplyImpl(
280280
std::vector<acl::ValkeyAclGetUserReplyView> &acl_views,
281-
RedisModuleCallReply *reply) {
281+
ValkeyModuleCallReply *reply) {
282282
acl_views.emplace_back(acl::ValkeyAclGetUserReplyView{});
283283
auto &acl_view = acl_views.back();
284284

285-
RedisModuleCallReply *map_key;
286-
RedisModuleCallReply *map_val;
285+
ValkeyModuleCallReply *map_key;
286+
ValkeyModuleCallReply *map_val;
287287
int idx = 0;
288288

289-
while (RedisModule_CallReplyMapElement(reply, idx, &map_key, &map_val) ==
290-
REDISMODULE_OK) {
289+
while (ValkeyModule_CallReplyMapElement(reply, idx, &map_key, &map_val) ==
290+
VALKEYMODULE_OK) {
291291
if (map_key &&
292-
RedisModule_CallReplyType(map_key) == REDISMODULE_REPLY_STRING) {
292+
ValkeyModule_CallReplyType(map_key) == VALKEYMODULE_REPLY_STRING) {
293293
absl::string_view key = CallReplyStringToStringView(map_key);
294294

295295
if (absl::EqualsIgnoreCase(key, "commands")) {
@@ -298,9 +298,9 @@ void GetAclViewFromCallReplyImpl(
298298
acl_view.keys = CallReplyStringToStringView(map_val);
299299
} else if (absl::EqualsIgnoreCase(key, "selectors")) {
300300
int selector_idx = 0;
301-
RedisModuleCallReply *selector_reply;
302-
while ((selector_reply =
303-
RedisModule_CallReplyArrayElement(map_val, selector_idx))) {
301+
ValkeyModuleCallReply *selector_reply;
302+
while ((selector_reply = ValkeyModule_CallReplyArrayElement(
303+
map_val, selector_idx))) {
304304
GetAclViewFromCallReplyImpl(acl_views, selector_reply);
305305
selector_idx++;
306306
}
@@ -313,8 +313,8 @@ void GetAclViewFromCallReplyImpl(
313313
} // namespace
314314

315315
absl::StatusOr<std::vector<acl::ValkeyAclGetUserReplyView>>
316-
GetAclViewFromCallReply(RedisModuleCallReply *reply) {
317-
if (!reply || RedisModule_CallReplyType(reply) != REDISMODULE_REPLY_MAP) {
316+
GetAclViewFromCallReply(ValkeyModuleCallReply *reply) {
317+
if (!reply || ValkeyModule_CallReplyType(reply) != VALKEYMODULE_REPLY_MAP) {
318318
return absl::FailedPreconditionError(
319319
"Cannot get an ACL from the server, got an invalid response");
320320
}
@@ -325,15 +325,16 @@ GetAclViewFromCallReply(RedisModuleCallReply *reply) {
325325
}
326326

327327
absl::Status AclPrefixCheck(
328-
RedisModuleCtx *ctx,
328+
ValkeyModuleCtx *ctx,
329329
const absl::flat_hash_set<absl::string_view> &module_allowed_cmds,
330330
const std::vector<std::string> &module_prefixes) {
331331
if (!vmsdk::IsRealUserClient(ctx)) {
332332
return absl::OkStatus();
333333
}
334-
auto username = vmsdk::UniqueRedisString(RedisModule_GetCurrentUserName(ctx));
335-
auto reply = vmsdk::UniquePtrRedisCallReply(
336-
RedisModule_Call(ctx, "ACL", "cs3", "GETUSER", username.get()));
334+
auto username =
335+
vmsdk::UniqueValkeyString(ValkeyModule_GetCurrentUserName(ctx));
336+
auto reply = vmsdk::UniquePtrValkeyCallReply(
337+
ValkeyModule_Call(ctx, "ACL", "cs3", "GETUSER", username.get()));
337338
VMSDK_ASSIGN_OR_RETURN(auto acl_views, GetAclViewFromCallReply(reply.get()));
338339

339340
auto acl_keys = GetKeysWithAllowedCommands(module_allowed_cmds, acl_views);
@@ -354,7 +355,7 @@ absl::Status AclPrefixCheck(
354355
}
355356

356357
absl::Status AclPrefixCheck(
357-
RedisModuleCtx *ctx,
358+
ValkeyModuleCtx *ctx,
358359
const absl::flat_hash_set<absl::string_view> &module_allowed_cmds,
359360
const data_model::IndexSchema &index_schema_proto) {
360361
std::vector<std::string> module_prefixes;

src/acl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Check if
2929
* according to the ACL rules defined in the server.
3030
*/
3131
absl::Status AclPrefixCheck(
32-
RedisModuleCtx *ctx,
32+
ValkeyModuleCtx *ctx,
3333
const absl::flat_hash_set<absl::string_view> &module_allowed_cmds,
3434
const std::vector<std::string> &module_prefixes);
3535

3636
absl::Status AclPrefixCheck(
37-
RedisModuleCtx *ctx,
37+
ValkeyModuleCtx *ctx,
3838
const absl::flat_hash_set<absl::string_view> &module_allowed_cmds,
3939
const data_model::IndexSchema &index_schema_proto);
4040

src/attribute.h

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
/*
2-
* Copyright (c) 2025, ValkeySearch contributors
2+
* Copyright (c) 2025, valkey-search contributors
33
* All rights reserved.
4+
* SPDX-License-Identifier: BSD 3-Clause
45
*
5-
* Redistribution and use in source and binary forms, with or without
6-
* modification, are permitted provided that the following conditions are met:
7-
*
8-
* * Redistributions of source code must retain the above copyright notice,
9-
* this list of conditions and the following disclaimer.
10-
* * Redistributions in binary form must reproduce the above copyright
11-
* notice, this list of conditions and the following disclaimer in the
12-
* documentation and/or other materials provided with the distribution.
13-
* * Neither the name of Redis nor the names of its contributors may be used
14-
* to endorse or promote products derived from this software without
15-
* specific prior written permission.
16-
*
17-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27-
* POSSIBILITY OF SUCH DAMAGE.
286
*/
297

308
#ifndef VALKEYSEARCH_SRC_ATTRIBUTE_H_
@@ -57,31 +35,31 @@ class Attribute {
5735
attribute_proto->set_allocated_index(index_->ToProto().release());
5836
return attribute_proto;
5937
}
60-
inline int RespondWithInfo(RedisModuleCtx* ctx) const {
61-
RedisModule_ReplyWithArray(ctx, REDISMODULE_POSTPONED_LEN);
62-
RedisModule_ReplyWithSimpleString(ctx, "identifier");
63-
RedisModule_ReplyWithSimpleString(ctx, GetIdentifier().c_str());
64-
RedisModule_ReplyWithSimpleString(ctx, "attribute");
65-
RedisModule_ReplyWithSimpleString(ctx, GetAlias().c_str());
38+
inline int RespondWithInfo(ValkeyModuleCtx* ctx) const {
39+
ValkeyModule_ReplyWithArray(ctx, VALKEYMODULE_POSTPONED_LEN);
40+
ValkeyModule_ReplyWithSimpleString(ctx, "identifier");
41+
ValkeyModule_ReplyWithSimpleString(ctx, GetIdentifier().c_str());
42+
ValkeyModule_ReplyWithSimpleString(ctx, "attribute");
43+
ValkeyModule_ReplyWithSimpleString(ctx, GetAlias().c_str());
6644
int added_fields = index_->RespondWithInfo(ctx);
67-
RedisModule_ReplySetArrayLength(ctx, added_fields + 4);
45+
ValkeyModule_ReplySetArrayLength(ctx, added_fields + 4);
6846
return 1;
6947
}
7048

71-
inline vmsdk::UniqueRedisString DefaultReplyScoreAs() const {
49+
inline vmsdk::UniqueValkeyString DefaultReplyScoreAs() const {
7250
if (!cached_score_as_) {
7351
cached_score_as_ =
74-
vmsdk::MakeUniqueRedisString(absl::StrCat("__", alias_, "_score"));
52+
vmsdk::MakeUniqueValkeyString(absl::StrCat("__", alias_, "_score"));
7553
}
76-
return vmsdk::RetainUniqueRedisString(cached_score_as_.get());
54+
return vmsdk::RetainUniqueValkeyString(cached_score_as_.get());
7755
}
7856

7957
private:
8058
std::string alias_;
8159
std::string identifier_;
8260
std::shared_ptr<indexes::IndexBase> index_;
8361
// Maintaining a cached version
84-
mutable vmsdk::UniqueRedisString cached_score_as_;
62+
mutable vmsdk::UniqueValkeyString cached_score_as_;
8563
};
8664

8765
} // namespace valkey_search

src/attribute_data_type.cc

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
/*
2-
* Copyright (c) 2025, ValkeySearch contributors
2+
* Copyright (c) 2025, valkey-search contributors
33
* All rights reserved.
4+
* SPDX-License-Identifier: BSD 3-Clause
45
*
5-
* Redistribution and use in source and binary forms, with or without
6-
* modification, are permitted provided that the following conditions are met:
7-
*
8-
* * Redistributions of source code must retain the above copyright notice,
9-
* this list of conditions and the following disclaimer.
10-
* * Redistributions in binary form must reproduce the above copyright
11-
* notice, this list of conditions and the following disclaimer in the
12-
* documentation and/or other materials provided with the distribution.
13-
* * Neither the name of Redis nor the names of its contributors may be used
14-
* to endorse or promote products derived from this software without
15-
* specific prior written permission.
16-
*
17-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27-
* POSSIBILITY OF SUCH DAMAGE.
286
*/
297

308
#include "src/attribute_data_type.h"
@@ -45,27 +23,27 @@
4523
#include "vmsdk/src/valkey_module_api/valkey_module.h"
4624

4725
namespace valkey_search {
48-
absl::StatusOr<vmsdk::UniqueRedisString> HashAttributeDataType::GetRecord(
49-
[[maybe_unused]] RedisModuleCtx *ctx, RedisModuleKey *open_key,
26+
absl::StatusOr<vmsdk::UniqueValkeyString> HashAttributeDataType::GetRecord(
27+
[[maybe_unused]] ValkeyModuleCtx *ctx, ValkeyModuleKey *open_key,
5028
[[maybe_unused]] absl::string_view key,
5129
absl::string_view identifier) const {
5230
vmsdk::VerifyMainThread();
53-
RedisModuleString *record{nullptr};
54-
RedisModule_HashGet(open_key, REDISMODULE_HASH_CFIELDS, identifier.data(),
55-
&record, nullptr);
31+
ValkeyModuleString *record{nullptr};
32+
ValkeyModule_HashGet(open_key, VALKEYMODULE_HASH_CFIELDS, identifier.data(),
33+
&record, nullptr);
5634
if (!record) {
5735
return absl::NotFoundError("No such record with identifier");
5836
}
59-
return vmsdk::UniqueRedisString(record);
37+
return vmsdk::UniqueValkeyString(record);
6038
}
6139

6240
struct HashScanCallbackData {
6341
const absl::flat_hash_set<absl::string_view> &identifiers;
6442
RecordsMap key_value_content;
6543
};
6644

67-
void HashScanCallback(RedisModuleKey *key, RedisModuleString *field,
68-
RedisModuleString *value, void *privdata) {
45+
void HashScanCallback(ValkeyModuleKey *key, ValkeyModuleString *field,
46+
ValkeyModuleString *value, void *privdata) {
6947
vmsdk::VerifyMainThread();
7048
if (!field || !value) {
7149
return;
@@ -78,26 +56,27 @@ void HashScanCallback(RedisModuleKey *key, RedisModuleString *field,
7856
if (callback_data->identifiers.empty() ||
7957
callback_data->identifiers.contains(field_str)) {
8058
callback_data->key_value_content.emplace(
81-
field_str, RecordsMapValue(vmsdk::RetainUniqueRedisString(field),
82-
vmsdk::RetainUniqueRedisString(value)));
59+
field_str, RecordsMapValue(vmsdk::RetainUniqueValkeyString(field),
60+
vmsdk::RetainUniqueValkeyString(value)));
8361
}
8462
}
8563

86-
bool HashHasRecord(RedisModuleKey *key, absl::string_view identifier) {
64+
bool HashHasRecord(ValkeyModuleKey *key, absl::string_view identifier) {
8765
int exists;
88-
RedisModule_HashGet(key, REDISMODULE_HASH_CFIELDS | REDISMODULE_HASH_EXISTS,
89-
identifier.data(), &exists, nullptr);
66+
ValkeyModule_HashGet(key,
67+
VALKEYMODULE_HASH_CFIELDS | VALKEYMODULE_HASH_EXISTS,
68+
identifier.data(), &exists, nullptr);
9069
return exists;
9170
}
9271

9372
absl::StatusOr<RecordsMap> HashAttributeDataType::FetchAllRecords(
94-
RedisModuleCtx *ctx, const std::string &vector_identifier,
73+
ValkeyModuleCtx *ctx, const std::string &vector_identifier,
9574
absl::string_view key,
9675
const absl::flat_hash_set<absl::string_view> &identifiers) const {
9776
vmsdk::VerifyMainThread();
98-
auto key_str = vmsdk::MakeUniqueRedisString(key);
77+
auto key_str = vmsdk::MakeUniqueValkeyString(key);
9978
auto key_obj =
100-
vmsdk::MakeUniqueRedisOpenKey(ctx, key_str.get(), REDISMODULE_READ);
79+
vmsdk::MakeUniqueValkeyOpenKey(ctx, key_str.get(), VALKEYMODULE_READ);
10180
if (!key_obj) {
10281
return absl::NotFoundError(
10382
absl::StrCat("No such record with key: `", vector_identifier, "`"));
@@ -106,10 +85,10 @@ absl::StatusOr<RecordsMap> HashAttributeDataType::FetchAllRecords(
10685
return absl::NotFoundError(absl::StrCat("No such record with identifier: `",
10786
vector_identifier, "`"));
10887
}
109-
vmsdk::UniqueRedisScanCursor cursor = vmsdk::MakeUniqueRedisScanCursor();
88+
vmsdk::UniqueValkeyScanCursor cursor = vmsdk::MakeUniqueValkeyScanCursor();
11089
HashScanCallbackData callback_data{identifiers};
111-
while (RedisModule_ScanKey(key_obj.get(), cursor.get(), HashScanCallback,
112-
&callback_data)) {
90+
while (ValkeyModule_ScanKey(key_obj.get(), cursor.get(), HashScanCallback,
91+
&callback_data)) {
11392
}
11493
return std::move(callback_data.key_value_content);
11594
}
@@ -121,7 +100,7 @@ absl::string_view TrimBrackets(absl::string_view record) {
121100
return record;
122101
}
123102

124-
absl::StatusOr<vmsdk::UniqueRedisString> NormalizeJsonRecord(
103+
absl::StatusOr<vmsdk::UniqueValkeyString> NormalizeJsonRecord(
125104
absl::string_view record) {
126105
if (!record.empty() && record[0] != '[') {
127106
return absl::NotFoundError("Invalid record");
@@ -135,40 +114,40 @@ absl::StatusOr<vmsdk::UniqueRedisString> NormalizeJsonRecord(
135114
if (record.empty()) {
136115
return absl::NotFoundError("Empty record");
137116
}
138-
return vmsdk::MakeUniqueRedisString(record);
117+
return vmsdk::MakeUniqueValkeyString(record);
139118
}
140119

141-
absl::StatusOr<vmsdk::UniqueRedisString> JsonAttributeDataType::GetRecord(
142-
RedisModuleCtx *ctx, [[maybe_unused]] RedisModuleKey *open_key,
120+
absl::StatusOr<vmsdk::UniqueValkeyString> JsonAttributeDataType::GetRecord(
121+
ValkeyModuleCtx *ctx, [[maybe_unused]] ValkeyModuleKey *open_key,
143122
absl::string_view key, absl::string_view identifier) const {
144123
vmsdk::VerifyMainThread();
145124

146-
auto reply = vmsdk::UniquePtrRedisCallReply(RedisModule_Call(
125+
auto reply = vmsdk::UniquePtrValkeyCallReply(ValkeyModule_Call(
147126
ctx, kJsonCmd.data(), "cc", key.data(), identifier.data()));
148127
if (reply == nullptr) {
149128
return absl::NotFoundError(
150129
absl::StrCat("No such record with identifier: `", identifier, "`"));
151130
}
152-
auto reply_type = RedisModule_CallReplyType(reply.get());
153-
if (reply_type == REDISMODULE_REPLY_STRING) {
154-
auto reply_str = vmsdk::UniqueRedisString(
155-
RedisModule_CreateStringFromCallReply(reply.get()));
131+
auto reply_type = ValkeyModule_CallReplyType(reply.get());
132+
if (reply_type == VALKEYMODULE_REPLY_STRING) {
133+
auto reply_str = vmsdk::UniqueValkeyString(
134+
ValkeyModule_CreateStringFromCallReply(reply.get()));
156135
return NormalizeJsonRecord(vmsdk::ToStringView(reply_str.get()));
157136
}
158137
return absl::NotFoundError("Json.get returned a non string value");
159138
}
160139

161140
absl::StatusOr<RecordsMap> JsonAttributeDataType::FetchAllRecords(
162-
RedisModuleCtx *ctx, const std::string &vector_identifier,
141+
ValkeyModuleCtx *ctx, const std::string &vector_identifier,
163142
absl::string_view key,
164143
const absl::flat_hash_set<absl::string_view> &identifiers) const {
165144
vmsdk::VerifyMainThread();
166145
// Validating that a JSON object with the key exists with the vector
167146
// identifier
168-
auto reply = vmsdk::UniquePtrRedisCallReply(RedisModule_Call(
147+
auto reply = vmsdk::UniquePtrValkeyCallReply(ValkeyModule_Call(
169148
ctx, kJsonCmd.data(), "cc", key.data(), vector_identifier.c_str()));
170149
if (reply == nullptr ||
171-
RedisModule_CallReplyType(reply.get()) != REDISMODULE_REPLY_STRING) {
150+
ValkeyModule_CallReplyType(reply.get()) != VALKEYMODULE_REPLY_STRING) {
172151
return absl::NotFoundError(absl::StrCat("No such record with identifier: `",
173152
vector_identifier, "`"));
174153
}
@@ -179,13 +158,13 @@ absl::StatusOr<RecordsMap> JsonAttributeDataType::FetchAllRecords(
179158
continue;
180159
}
181160
key_value_content.emplace(
182-
identifier, RecordsMapValue(vmsdk::MakeUniqueRedisString(identifier),
161+
identifier, RecordsMapValue(vmsdk::MakeUniqueValkeyString(identifier),
183162
std::move(str.value())));
184163
}
185164
return key_value_content;
186165
}
187166

188-
bool IsJsonModuleLoaded(RedisModuleCtx *ctx) {
167+
bool IsJsonModuleLoaded(ValkeyModuleCtx *ctx) {
189168
return vmsdk::IsModuleLoaded(ctx, "json");
190169
}
191170
} // namespace valkey_search

0 commit comments

Comments
 (0)