@@ -12,12 +12,12 @@ use serde_json::Value;
12
12
use crate :: {
13
13
commands:: { FoundIndex , ObjectLen , Values } ,
14
14
error:: Error ,
15
- formatter:: { FormatOptions , RedisJsonFormatter } ,
15
+ formatter:: { RedisJsonFormatter , ReplyFormatOptions } ,
16
16
manager:: {
17
17
err_msg_json_expected, err_msg_json_path_doesnt_exist_with_param, AddUpdateInfo ,
18
18
SetUpdateInfo , UpdateInfo ,
19
19
} ,
20
- redisjson:: { normalize_arr_indices, Format , Path , SetOptions } ,
20
+ redisjson:: { normalize_arr_indices, Path , ReplyFormat , SetOptions } ,
21
21
} ;
22
22
23
23
pub struct KeyValue < ' a , V : SelectValue > {
@@ -98,7 +98,7 @@ impl<'a, V: SelectValue + 'a> KeyValue<'a, V> {
98
98
Ok ( results)
99
99
}
100
100
101
- pub fn serialize_object < O : Serialize > ( o : & O , format : & FormatOptions ) -> String {
101
+ pub fn serialize_object < O : Serialize > ( o : & O , format : & ReplyFormatOptions ) -> String {
102
102
// When using the default formatting, we can use serde_json's default serializer
103
103
if format. no_formatting ( ) {
104
104
serde_json:: to_string ( o) . unwrap ( )
@@ -113,7 +113,7 @@ impl<'a, V: SelectValue + 'a> KeyValue<'a, V> {
113
113
fn to_json_multi (
114
114
& self ,
115
115
paths : & mut Vec < Path > ,
116
- format : & FormatOptions ,
116
+ format : & ReplyFormatOptions ,
117
117
is_legacy : bool ,
118
118
) -> Result < RedisValue , Error > {
119
119
// TODO: Creating a temp doc here duplicates memory usage. This can be very memory inefficient.
@@ -177,7 +177,11 @@ impl<'a, V: SelectValue + 'a> KeyValue<'a, V> {
177
177
Ok ( res)
178
178
}
179
179
180
- fn to_resp3 ( & self , paths : & mut Vec < Path > , format : & FormatOptions ) -> Result < RedisValue , Error > {
180
+ fn to_resp3 (
181
+ & self ,
182
+ paths : & mut Vec < Path > ,
183
+ format : & ReplyFormatOptions ,
184
+ ) -> Result < RedisValue , Error > {
181
185
let results = paths
182
186
. drain ( ..)
183
187
. map ( |path : Path | self . to_resp3_path ( & path, format) )
@@ -186,7 +190,7 @@ impl<'a, V: SelectValue + 'a> KeyValue<'a, V> {
186
190
Ok ( RedisValue :: Array ( results) )
187
191
}
188
192
189
- pub fn to_resp3_path ( & self , path : & Path , format : & FormatOptions ) -> RedisValue {
193
+ pub fn to_resp3_path ( & self , path : & Path , format : & ReplyFormatOptions ) -> RedisValue {
190
194
compile ( path. get_path ( ) ) . map_or_else (
191
195
|_| RedisValue :: Array ( vec ! [ ] ) ,
192
196
|q| Self :: values_to_resp3 ( & calc_once ( q, self . val ) , format) ,
@@ -196,7 +200,7 @@ impl<'a, V: SelectValue + 'a> KeyValue<'a, V> {
196
200
fn to_json_single (
197
201
& self ,
198
202
path : & str ,
199
- format : & FormatOptions ,
203
+ format : & ReplyFormatOptions ,
200
204
is_legacy : bool ,
201
205
) -> Result < RedisValue , Error > {
202
206
let res = if is_legacy {
@@ -210,16 +214,16 @@ impl<'a, V: SelectValue + 'a> KeyValue<'a, V> {
210
214
Ok ( res)
211
215
}
212
216
213
- fn values_to_resp3 ( values : & [ & V ] , format : & FormatOptions ) -> RedisValue {
217
+ fn values_to_resp3 ( values : & [ & V ] , format : & ReplyFormatOptions ) -> RedisValue {
214
218
values
215
219
. iter ( )
216
220
. map ( |v| Self :: value_to_resp3 ( v, format) )
217
221
. collect :: < Vec < RedisValue > > ( )
218
222
. into ( )
219
223
}
220
224
221
- pub fn value_to_resp3 ( value : & V , format : & FormatOptions ) -> RedisValue {
222
- if format. format == Format :: EXPAND {
225
+ pub fn value_to_resp3 ( value : & V , format : & ReplyFormatOptions ) -> RedisValue {
226
+ if format. format == ReplyFormat :: EXPAND {
223
227
match value. get_type ( ) {
224
228
SelectValueType :: Null => RedisValue :: Null ,
225
229
SelectValueType :: Bool => RedisValue :: Bool ( value. get_bool ( ) ) ,
@@ -260,11 +264,8 @@ impl<'a, V: SelectValue + 'a> KeyValue<'a, V> {
260
264
pub fn to_json (
261
265
& self ,
262
266
paths : & mut Vec < Path > ,
263
- format : & FormatOptions ,
267
+ format : & ReplyFormatOptions ,
264
268
) -> Result < RedisValue , Error > {
265
- if format. format == Format :: BSON {
266
- return Err ( "ERR Soon to come..." . into ( ) ) ;
267
- }
268
269
let is_legacy = !paths. iter ( ) . any ( |p| !p. is_legacy ( ) ) ;
269
270
270
271
// If we're using RESP3, we need to reply with an array of values
@@ -351,12 +352,20 @@ impl<'a, V: SelectValue + 'a> KeyValue<'a, V> {
351
352
}
352
353
}
353
354
354
- pub fn to_string_single ( & self , path : & str , format : & FormatOptions ) -> Result < String , Error > {
355
+ pub fn to_string_single (
356
+ & self ,
357
+ path : & str ,
358
+ format : & ReplyFormatOptions ,
359
+ ) -> Result < String , Error > {
355
360
let result = self . get_first ( path) ?;
356
361
Ok ( Self :: serialize_object ( & result, format) )
357
362
}
358
363
359
- pub fn to_string_multi ( & self , path : & str , format : & FormatOptions ) -> Result < String , Error > {
364
+ pub fn to_string_multi (
365
+ & self ,
366
+ path : & str ,
367
+ format : & ReplyFormatOptions ,
368
+ ) -> Result < String , Error > {
360
369
let results = self . get_values ( path) ?;
361
370
Ok ( Self :: serialize_object ( & results, format) )
362
371
}
0 commit comments