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"
4523#include " vmsdk/src/valkey_module_api/valkey_module.h"
4624
4725namespace 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
6240struct 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
9372absl::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
161140absl::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