@@ -9,7 +9,7 @@ use crate::commands::bloom_util::{BloomFilterType, ERROR};
9
9
// TODO: Replace string literals in error messages with static
10
10
// TODO: Check all int / usize casting.
11
11
12
- pub fn bloom_filter_add_value ( ctx : & Context , input_args : & Vec < RedisString > , multi : bool ) -> RedisResult {
12
+ pub fn bloom_filter_add_value ( ctx : & Context , input_args : & [ RedisString ] , multi : bool ) -> RedisResult {
13
13
let argc = input_args. len ( ) ;
14
14
if ( !multi && argc != 3 ) || argc < 3 {
15
15
return Err ( RedisError :: WrongArity ) ;
@@ -29,13 +29,12 @@ pub fn bloom_filter_add_value(ctx: &Context, input_args: &Vec<RedisString>, mult
29
29
match value {
30
30
Some ( bf) => {
31
31
if !multi {
32
- let item = & input_args[ curr_cmd_idx] ;
32
+ let item = input_args[ curr_cmd_idx] . as_slice ( ) ;
33
33
return Ok ( RedisValue :: Integer ( bf. add_item ( item) ) ) ;
34
34
}
35
35
let mut result = Vec :: new ( ) ;
36
- for idx in curr_cmd_idx..argc {
37
- let item = & input_args[ idx] ;
38
- result. push ( RedisValue :: Integer ( bf. add_item ( item) ) ) ;
36
+ for item in input_args. iter ( ) . take ( argc) . skip ( curr_cmd_idx) {
37
+ result. push ( RedisValue :: Integer ( bf. add_item ( item. as_slice ( ) ) ) ) ;
39
38
}
40
39
Ok ( RedisValue :: Array ( result) )
41
40
}
@@ -49,14 +48,13 @@ pub fn bloom_filter_add_value(ctx: &Context, input_args: &Vec<RedisString>, mult
49
48
let result = match multi {
50
49
true => {
51
50
let mut result = Vec :: new ( ) ;
52
- for idx in curr_cmd_idx..argc {
53
- let item = & input_args[ idx] ;
54
- result. push ( RedisValue :: Integer ( bf. add_item ( item) ) ) ;
51
+ for item in input_args. iter ( ) . take ( argc) . skip ( curr_cmd_idx) {
52
+ result. push ( RedisValue :: Integer ( bf. add_item ( item. as_slice ( ) ) ) ) ;
55
53
}
56
54
Ok ( RedisValue :: Array ( result) )
57
55
}
58
56
false => {
59
- let item = & input_args[ curr_cmd_idx] ;
57
+ let item = input_args[ curr_cmd_idx] . as_slice ( ) ;
60
58
Ok ( RedisValue :: Integer ( bf. add_item ( item) ) )
61
59
}
62
60
} ;
@@ -70,7 +68,7 @@ pub fn bloom_filter_add_value(ctx: &Context, input_args: &Vec<RedisString>, mult
70
68
}
71
69
}
72
70
73
- pub fn bloom_filter_exists ( ctx : & Context , input_args : & Vec < RedisString > , multi : bool ) -> RedisResult {
71
+ pub fn bloom_filter_exists ( ctx : & Context , input_args : & [ RedisString ] , multi : bool ) -> RedisResult {
74
72
let argc = input_args. len ( ) ;
75
73
if ( !multi && argc != 3 ) || argc < 3 {
76
74
return Err ( RedisError :: WrongArity ) ;
@@ -88,12 +86,12 @@ pub fn bloom_filter_exists(ctx: &Context, input_args: &Vec<RedisString>, multi:
88
86
}
89
87
} ;
90
88
if !multi {
91
- let item = & input_args[ curr_cmd_idx] ;
89
+ let item = input_args[ curr_cmd_idx] . as_slice ( ) ;
92
90
return Ok ( bloom_filter_item_exists ( value, item) ) ;
93
91
}
94
92
let mut result = Vec :: new ( ) ;
95
93
while curr_cmd_idx < argc {
96
- let item = & input_args[ curr_cmd_idx] ;
94
+ let item = input_args[ curr_cmd_idx] . as_slice ( ) ;
97
95
result. push ( bloom_filter_item_exists ( value, item) ) ;
98
96
curr_cmd_idx += 1 ;
99
97
}
@@ -112,7 +110,7 @@ fn bloom_filter_item_exists(value: Option<&BloomFilterType>, item: &[u8]) -> Red
112
110
RedisValue :: Integer ( 0 )
113
111
}
114
112
115
- pub fn bloom_filter_card ( ctx : & Context , input_args : & Vec < RedisString > ) -> RedisResult {
113
+ pub fn bloom_filter_card ( ctx : & Context , input_args : & [ RedisString ] ) -> RedisResult {
116
114
let argc = input_args. len ( ) ;
117
115
if argc != 2 {
118
116
return Err ( RedisError :: WrongArity ) ;
@@ -133,7 +131,7 @@ pub fn bloom_filter_card(ctx: &Context, input_args: &Vec<RedisString>) -> RedisR
133
131
}
134
132
}
135
133
136
- pub fn bloom_filter_reserve ( ctx : & Context , input_args : & Vec < RedisString > ) -> RedisResult {
134
+ pub fn bloom_filter_reserve ( ctx : & Context , input_args : & [ RedisString ] ) -> RedisResult {
137
135
let argc = input_args. len ( ) ;
138
136
if !( 4 ..=6 ) . contains ( & argc) {
139
137
return Err ( RedisError :: WrongArity ) ;
@@ -202,7 +200,7 @@ pub fn bloom_filter_reserve(ctx: &Context, input_args: &Vec<RedisString>) -> Red
202
200
}
203
201
}
204
202
205
- pub fn bloom_filter_insert ( ctx : & Context , input_args : & Vec < RedisString > ) -> RedisResult {
203
+ pub fn bloom_filter_insert ( ctx : & Context , input_args : & [ RedisString ] ) -> RedisResult {
206
204
let argc = input_args. len ( ) ;
207
205
// At the very least, we need: BF.INSERT <key> ITEM <item>
208
206
if argc < 4 {
@@ -276,9 +274,8 @@ pub fn bloom_filter_insert(ctx: &Context, input_args: &Vec<RedisString>) -> Redi
276
274
let mut result = Vec :: new ( ) ;
277
275
match value {
278
276
Some ( bf) => {
279
- for i in idx..argc {
280
- let item = & input_args[ i] ;
281
- result. push ( RedisValue :: Integer ( bf. add_item ( item) ) ) ;
277
+ for item in input_args. iter ( ) . take ( argc) . skip ( idx) {
278
+ result. push ( RedisValue :: Integer ( bf. add_item ( item. as_slice ( ) ) ) ) ;
282
279
}
283
280
Ok ( RedisValue :: Array ( result) )
284
281
}
@@ -287,9 +284,8 @@ pub fn bloom_filter_insert(ctx: &Context, input_args: &Vec<RedisString>) -> Redi
287
284
return Err ( RedisError :: Str ( "ERR not found" ) ) ;
288
285
}
289
286
let mut bf = BloomFilterType :: new_reserved ( fp_rate, capacity, expansion) ;
290
- for i in idx..argc {
291
- let item = & input_args[ i] ;
292
- result. push ( RedisValue :: Integer ( bf. add_item ( item) ) ) ;
287
+ for item in input_args. iter ( ) . take ( argc) . skip ( idx) {
288
+ result. push ( RedisValue :: Integer ( bf. add_item ( item. as_slice ( ) ) ) ) ;
293
289
}
294
290
match filter_key. set_value ( & BLOOM_FILTER_TYPE , bf) {
295
291
Ok ( _) => {
@@ -303,7 +299,7 @@ pub fn bloom_filter_insert(ctx: &Context, input_args: &Vec<RedisString>) -> Redi
303
299
}
304
300
}
305
301
306
- pub fn bloom_filter_info ( ctx : & Context , input_args : & Vec < RedisString > ) -> RedisResult {
302
+ pub fn bloom_filter_info ( ctx : & Context , input_args : & [ RedisString ] ) -> RedisResult {
307
303
let argc = input_args. len ( ) ;
308
304
if !( 2 ..=3 ) . contains ( & argc) {
309
305
return Err ( RedisError :: WrongArity ) ;
@@ -346,16 +342,17 @@ pub fn bloom_filter_info(ctx: &Context, input_args: &Vec<RedisString>) -> RedisR
346
342
}
347
343
}
348
344
Some ( val) if argc == 2 => {
349
- let mut result = Vec :: new ( ) ;
350
- result. push ( RedisValue :: SimpleStringStatic ( "Capacity" ) ) ;
351
- result. push ( RedisValue :: Integer ( val. capacity ( ) ) ) ;
352
- result. push ( RedisValue :: SimpleStringStatic ( "Size" ) ) ;
353
- result. push ( RedisValue :: Integer ( val. get_memory_usage ( ) as i64 ) ) ;
354
- result. push ( RedisValue :: SimpleStringStatic ( "Number of filters" ) ) ;
355
- result. push ( RedisValue :: Integer ( val. filters . len ( ) as i64 ) ) ;
356
- result. push ( RedisValue :: SimpleStringStatic ( "Number of items inserted" ) ) ;
357
- result. push ( RedisValue :: Integer ( val. cardinality ( ) ) ) ;
358
- result. push ( RedisValue :: SimpleStringStatic ( "Expansion rate" ) ) ;
345
+ let mut result = vec ! [
346
+ RedisValue :: SimpleStringStatic ( "Capacity" ) ,
347
+ RedisValue :: Integer ( val. capacity( ) ) ,
348
+ RedisValue :: SimpleStringStatic ( "Size" ) ,
349
+ RedisValue :: Integer ( val. get_memory_usage( ) as i64 ) ,
350
+ RedisValue :: SimpleStringStatic ( "Number of filters" ) ,
351
+ RedisValue :: Integer ( val. filters. len( ) as i64 ) ,
352
+ RedisValue :: SimpleStringStatic ( "Number of items inserted" ) ,
353
+ RedisValue :: Integer ( val. cardinality( ) ) ,
354
+ RedisValue :: SimpleStringStatic ( "Expansion rate" ) ,
355
+ ] ;
359
356
if val. expansion == 0 {
360
357
result. push ( RedisValue :: Integer ( -1 ) ) ;
361
358
} else {
0 commit comments