-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathserver_commands.rs
2463 lines (2280 loc) · 83.4 KB
/
server_commands.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use crate::{
client::{prepare_command, PreparedCommand},
resp::{
cmd, CollectionResponse, CommandArgs, KeyValueArgsCollection, KeyValueCollectionResponse,
PrimitiveResponse, SingleArg, SingleArgCollection, ToArgs, Value,
},
Error, Result,
};
use serde::{
de::{self, DeserializeOwned, SeqAccess, Visitor},
Deserialize, Deserializer,
};
use std::{collections::HashMap, fmt, str::FromStr};
/// A group of Redis commands related to Server Management
/// # See Also
/// [Redis Server Management Commands](https://redis.io/commands/?group=server)
/// [ACL guide](https://redis.io/docs/manual/security/acl/)
pub trait ServerCommands<'a> {
/// The command shows the available ACL categories if called without arguments.
/// If a category name is given, the command shows all the Redis commands in the specified category.
///
/// # Return
/// A collection of ACL categories or a collection of commands inside a given category.
///
/// # Errors
/// The command may return an error if an invalid category name is given as argument.
///
/// # See Also
/// [<https://redis.io/commands/acl-cat/>](https://redis.io/commands/acl-cat/)
fn acl_cat<C, CC>(self, options: AclCatOptions) -> PreparedCommand<'a, Self, CC>
where
Self: Sized,
C: PrimitiveResponse + DeserializeOwned,
CC: CollectionResponse<C>,
{
prepare_command(self, cmd("ACL").arg("CAT").arg(options))
}
/// Delete all the specified ACL users and terminate all
/// the connections that are authenticated with such users.
///
/// # Return
/// The number of users that were deleted.
/// This number will not always match the number of arguments since certain users may not exist.
///
/// # See Also
/// [<https://redis.io/commands/acl-deluser/>](https://redis.io/commands/acl-deluser/)
fn acl_deluser<U, UU>(self, usernames: UU) -> PreparedCommand<'a, Self, usize>
where
Self: Sized,
U: SingleArg,
UU: SingleArgCollection<U>,
{
prepare_command(self, cmd("ACL").arg("DELUSER").arg(usernames))
}
/// Simulate the execution of a given command by a given user.
///
/// # Return
/// OK on success.
/// An error describing why the user can't execute the command.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::{ServerCommands, AclDryRunOptions},
/// # resp::cmd,
/// # Result,
/// # };
/// #
/// # #[cfg_attr(feature = "tokio-runtime", tokio::main)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::main)]
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// # client.acl_setuser("VIRGINIA", ["+SET", "~*"]).await?;
/// client
/// .acl_dryrun(
/// "VIRGINIA",
/// "SET",
/// AclDryRunOptions::default().arg("foo").arg("bar"),
/// )
/// .await?;
///
/// let result: String = client
/// .acl_dryrun(
/// "VIRGINIA",
/// "GET",
/// AclDryRunOptions::default().arg("foo")
/// )
/// .await?;
///
/// assert_eq!(
/// "User VIRGINIA has no permissions to run the 'get' command",
/// result
/// );
/// # client.acl_deluser("VIRGINIA").await?;
/// # Ok(())
/// # }
/// ```
///
/// # See Also
/// [<https://redis.io/commands/acl-dryrun/>](https://redis.io/commands/acl-dryrun/)
fn acl_dryrun<U, C, R>(
self,
username: U,
command: C,
options: AclDryRunOptions,
) -> PreparedCommand<'a, Self, R>
where
Self: Sized,
U: SingleArg,
C: SingleArg,
R: PrimitiveResponse,
{
prepare_command(
self,
cmd("ACL")
.arg("DRYRUN")
.arg(username)
.arg(command)
.arg(options),
)
}
/// Generates a password starting from /dev/urandom if available,
/// otherwise (in systems without /dev/urandom) it uses a weaker
/// system that is likely still better than picking a weak password by hand.
///
/// # Return
/// by default 64 bytes string representing 256 bits of pseudorandom data.
/// Otherwise if an argument if needed, the output string length is the number
/// of specified bits (rounded to the next multiple of 4) divided by 4.
///
/// # See Also
/// [<https://redis.io/commands/acl-genpass/>](https://redis.io/commands/acl-genpass/)
fn acl_genpass<R: PrimitiveResponse>(
self,
options: AclGenPassOptions,
) -> PreparedCommand<'a, Self, R>
where
Self: Sized,
{
prepare_command(self, cmd("ACL").arg("GENPASS").arg(options))
}
/// The command returns all the rules defined for an existing ACL user.
///
/// # Return
/// A collection of ACL rule definitions for the user.
///
/// # See Also
/// [<https://redis.io/commands/acl-getuser/>](https://redis.io/commands/acl-getuser/)
fn acl_getuser<U, RR>(self, username: U) -> PreparedCommand<'a, Self, RR>
where
Self: Sized,
U: SingleArg,
RR: KeyValueCollectionResponse<String, Value>,
{
prepare_command(self, cmd("ACL").arg("GETUSER").arg(username))
}
/// The command returns a helpful text describing the different ACL subcommands.
///
/// # Return
/// An array of strings.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::{Client, ClientPreparedCommand},
/// # commands::{FlushingMode, GetExOptions, GenericCommands, ServerCommands, StringCommands},
/// # resp::cmd,
/// # Result,
/// # };
/// #
/// # #[cfg_attr(feature = "tokio-runtime", tokio::main)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::main)]
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// let result: Vec<String> = client.acl_help().await?;
/// assert!(result.iter().any(|e| e == "HELP"));
/// # Ok(())
/// # }
/// ```
/// # See Also
/// [<https://redis.io/commands/acl-help/>](https://redis.io/commands/acl-help/)
fn acl_help(self) -> PreparedCommand<'a, Self, Vec<String>>
where
Self: Sized,
{
prepare_command(self, cmd("ACL").arg("HELP"))
}
/// The command shows the currently active ACL rules in the Redis server.
///
/// # Return
/// An array of strings.
/// Each line in the returned array defines a different user, and the
/// format is the same used in the redis.conf file or the external ACL file
///
/// # See Also
/// [<https://redis.io/commands/acl-list/>](https://redis.io/commands/acl-list/)
fn acl_list(self) -> PreparedCommand<'a, Self, Vec<String>>
where
Self: Sized,
{
prepare_command(self, cmd("ACL").arg("LIST"))
}
/// When Redis is configured to use an ACL file (with the aclfile configuration option),
/// this command will reload the ACLs from the file, replacing all the current ACL rules
/// with the ones defined in the file.
///
/// # Return
/// An array of strings.
/// Each line in the returned array defines a different user, and the
/// format is the same used in the redis.conf file or the external ACL file
///
/// # Errors
/// The command may fail with an error for several reasons:
/// - if the file is not readable,
/// - if there is an error inside the file, and in such case the error will be reported to the user in the error.
/// - Finally the command will fail if the server is not configured to use an external ACL file.
///
/// # See Also
/// [<https://redis.io/commands/acl-load/>](https://redis.io/commands/acl-load/)
fn acl_load(self) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
{
prepare_command(self, cmd("ACL").arg("LOAD"))
}
/// The command shows a list of recent ACL security events
///
/// # Return
/// A key/value collection of ACL security events.
/// Empty collection when called with the [`reset`](AclLogOptions::reset) option
///
/// # See Also
/// [<https://redis.io/commands/acl-log/>](https://redis.io/commands/acl-log/)
fn acl_log<EE>(self, options: AclLogOptions) -> PreparedCommand<'a, Self, Vec<EE>>
where
Self: Sized,
EE: KeyValueCollectionResponse<String, Value> + DeserializeOwned,
{
prepare_command(self, cmd("ACL").arg("LOG").arg(options))
}
/// When Redis is configured to use an ACL file (with the aclfile configuration option),
/// this command will save the currently defined ACLs from the server memory to the ACL file.
///
/// # Errors
/// The command may fail with an error for several reasons:
/// - if the file cannot be written
/// - if the server is not configured to use an external ACL file.
///
/// # See Also
/// [<https://redis.io/commands/acl-save/>](https://redis.io/commands/acl-save/)
fn acl_save(self) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
{
prepare_command(self, cmd("ACL").arg("SAVE"))
}
/// Create an ACL user with the specified rules or modify the rules of an existing user.
///
/// # Errors
/// If the rules contain errors, the error is returned.
///
/// # See Also
/// [<https://redis.io/commands/acl-setuser/>](https://redis.io/commands/acl-setuser/)
fn acl_setuser<U, R, RR>(self, username: U, rules: RR) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
U: SingleArg,
R: SingleArg,
RR: SingleArgCollection<R>,
{
prepare_command(self, cmd("ACL").arg("SETUSER").arg(username).arg(rules))
}
/// The command shows a list of all the usernames of the currently configured users in the Redis ACL system.
///
/// # Return
/// A collection of usernames
///
/// # See Also
/// [<https://redis.io/commands/acl-users/>](https://redis.io/commands/acl-users/)
fn acl_users<U, UU>(self) -> PreparedCommand<'a, Self, UU>
where
Self: Sized,
U: PrimitiveResponse + DeserializeOwned,
UU: CollectionResponse<U>,
{
prepare_command(self, cmd("ACL").arg("USERS"))
}
/// Return the username the current connection is authenticated with.
///
/// # Return
/// The username of the current connection.
///
/// # See Also
/// [<https://redis.io/commands/acl-whoami/>](https://redis.io/commands/acl-whoami/)
fn acl_whoami<U: PrimitiveResponse>(self) -> PreparedCommand<'a, Self, U>
where
Self: Sized,
{
prepare_command(self, cmd("ACL").arg("WHOAMI"))
}
/// The command async rewrites the append-only file to disk.
///
/// # Return
/// Success text that the rewriting started/scheduled or error text.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::ServerCommands,
/// # Result,
/// # };
/// #
/// # #[cfg_attr(feature = "tokio-runtime", tokio::main)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::main)]
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// let result: String = client.bgrewriteaof().await?;
/// assert!(result.starts_with("Background append only file rewriting "));
/// # Ok(())
/// # }
/// ```
///
/// # See Also
/// [<https://redis.io/docs/latest/commands/bgrewriteaof/>](https://redis.io/docs/latest/commands/bgrewriteaof/)
fn bgrewriteaof<R>(self) -> PreparedCommand<'a, Self, R>
where
Self: Sized,
R: PrimitiveResponse,
{
prepare_command(self, cmd("BGREWRITEAOF"))
}
/// The command save the DB in background.
///
/// # Return
/// Success text if Ok status
/// An error text is returned if there is already a background save running
/// or if there is another non-background-save process running,
/// specifically an in-progress AOF rewrite.
///
/// See operation succeeded using the `client.lastsave` command.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::{ServerCommands, BgsaveOptions},
/// # Result,
/// # };
/// #
/// # #[cfg_attr(feature = "tokio-runtime", tokio::main)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::main)]
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// let result: String = client.bgsave(BgsaveOptions::default().schedule()).await?;
/// assert!(result.starts_with("Background saving "));
/// # Ok(())
/// # }
/// ```
///
/// # See Also
/// [<https://redis.io/commands/bgsave/>](https://redis.io/commands/bgsave/)
fn bgsave<R>(self, options: BgsaveOptions) -> PreparedCommand<'a, Self, R>
where
Self: Sized,
R: PrimitiveResponse,
{
prepare_command(self, cmd("BGSAVE").arg(options))
}
/// Return an array with details about every Redis command.
///
/// # Return
/// A nested list of command details.
/// The order of commands in the array is random.
///
/// # See Also
/// [<https://redis.io/commands/command/>](https://redis.io/commands/command/)
fn command(self) -> PreparedCommand<'a, Self, Vec<CommandInfo>>
where
Self: Sized,
{
prepare_command(self, cmd("COMMAND"))
}
/// Number of total commands in this Redis server.
///
/// # Return
/// number of commands returned by [`command`](ServerCommands::command)
///
/// # See Also
/// [<https://redis.io/commands/command-count/>](https://redis.io/commands/command-count/)
fn command_count(self) -> PreparedCommand<'a, Self, usize>
where
Self: Sized,
{
prepare_command(self, cmd("COMMAND").arg("COUNT"))
}
/// Number of total commands in this Redis server.
///
/// # Return
/// map key=command name, value=command doc
///
/// # See Also
/// [<https://redis.io/commands/command-docs/>](https://redis.io/commands/command-docs/)
fn command_docs<N, NN, DD>(self, command_names: NN) -> PreparedCommand<'a, Self, DD>
where
Self: Sized,
N: SingleArg,
NN: SingleArgCollection<N>,
DD: KeyValueCollectionResponse<String, CommandDoc>,
{
prepare_command(self, cmd("COMMAND").arg("DOCS").arg(command_names))
}
/// A helper command to let you find the keys from a full Redis command.
///
/// # Return
/// list of keys from your command.
///
/// # See Also
/// [<https://redis.io/commands/command-_getkeys/>](https://redis.io/commands/command-_getkeys/)
fn command_getkeys<A, AA, KK>(self, args: AA) -> PreparedCommand<'a, Self, KK>
where
Self: Sized,
A: SingleArg,
AA: SingleArgCollection<A>,
KK: CollectionResponse<String>,
{
prepare_command(self, cmd("COMMAND").arg("GETKEYS").arg(args))
}
/// A helper command to let you find the keys from a full Redis command together with flags indicating what each key is used for.
///
/// # Return
/// map of keys with their flags from your command.
///
/// # See Also
/// [<https://redis.io/commands/command-getkeysandflags/>](https://redis.io/commands/command-getkeysandflags/)
fn command_getkeysandflags<A, AA, KK>(self, args: AA) -> PreparedCommand<'a, Self, KK>
where
Self: Sized,
A: SingleArg,
AA: SingleArgCollection<A>,
KK: KeyValueCollectionResponse<String, Vec<String>>,
{
prepare_command(self, cmd("COMMAND").arg("GETKEYSANDFLAGS").arg(args))
}
/// The command returns a helpful text describing the different COMMAND subcommands.
///
/// # Return
/// The array strings.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::ServerCommands,
/// # Result,
/// # };
/// #
/// # #[cfg_attr(feature = "tokio-runtime", tokio::main)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::main)]
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// let result: Vec<String> = client.command_help().await?;
/// assert!(result.iter().any(|e| e == "HELP"));
/// # Ok(())
/// }
/// ```
///
/// # See Also
/// [<https://redis.io/docs/latest/commands/command-help/>](https://redis.io/docs/latest/commands/command-help/)
fn command_help(self) -> PreparedCommand<'a, Self, Vec<String>>
where
Self: Sized,
{
prepare_command(self, cmd("COMMAND").arg("HELP"))
}
/// Return an array with details about multiple Redis command.
///
/// # Return
/// A nested list of command details.
///
/// # See Also
/// [<https://redis.io/commands/command-info/>](https://redis.io/commands/command-info/)
fn command_info<N, NN>(self, command_names: NN) -> PreparedCommand<'a, Self, Vec<CommandInfo>>
where
Self: Sized,
N: SingleArg,
NN: SingleArgCollection<N>,
{
prepare_command(self, cmd("COMMAND").arg("INFO").arg(command_names))
}
/// Return an array of the server's command names based on optional filters
///
/// # Return
/// an array of the server's command names.
///
/// # See Also
/// [<https://redis.io/commands/command-list/>](https://redis.io/commands/command-list/)
fn command_list<CC>(self, options: CommandListOptions) -> PreparedCommand<'a, Self, CC>
where
Self: Sized,
CC: CollectionResponse<String>,
{
prepare_command(self, cmd("COMMAND").arg("LIST").arg(options))
}
/// Used to read the configuration parameters of a running Redis server.
///
/// For every key that does not hold a string value or does not exist,
/// the special value nil is returned. Because of this, the operation never fails.
///
/// # Return
/// Array reply: collection of the requested params with their matching values.
///
/// # See Also
/// [<https://redis.io/commands/config-get/>](https://redis.io/commands/config-get/)
#[must_use]
fn config_get<P, PP, V, VV>(self, params: PP) -> PreparedCommand<'a, Self, VV>
where
Self: Sized,
P: SingleArg,
PP: SingleArgCollection<P>,
V: PrimitiveResponse,
VV: KeyValueCollectionResponse<String, V>,
{
prepare_command(self, cmd("CONFIG").arg("GET").arg(params))
}
/// The command returns a helpful text describing the different CONFIG subcommands.
///
/// # Return
/// An array of strings.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::ServerCommands,
/// # Result,
/// # };
/// #
/// # #[cfg_attr(feature = "tokio-runtime", tokio::main)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::main)]
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// let result: Vec<String> = client.config_help().await?;
/// assert!(result.iter().any(|e| e == "HELP"));
/// # Ok(())
/// # }
/// ```
/// # See Also
/// [<https://redis.io/commands/config-help/>](https://redis.io/commands/config-help/)
#[must_use]
fn config_help(self) -> PreparedCommand<'a, Self, Vec<String>>
where
Self: Sized,
{
prepare_command(self, cmd("CONFIG").arg("HELP"))
}
/// Resets the statistics reported by Redis using the [`info`](ServerCommands::info) command.
///
/// # See Also
/// [<https://redis.io/commands/config-resetstat/>](https://redis.io/commands/config-resetstat/)
#[must_use]
fn config_resetstat(self) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
{
prepare_command(self, cmd("CONFIG").arg("RESETSTAT"))
}
/// Rewrites the redis.conf file the server was started with,
/// applying the minimal changes needed to make it reflect the configuration currently used by the server,
/// which may be different compared to the original one because of the use of the
/// [`config_set`](ServerCommands::config_set) command.
///
/// # See Also
/// [<https://redis.io/commands/config-rewrite/>](https://redis.io/commands/config-rewrite/)
#[must_use]
fn config_rewrite(self) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
{
prepare_command(self, cmd("CONFIG").arg("REWRITE"))
}
/// Used in order to reconfigure the server at run time without the need to restart Redis.
///
/// # See Also
/// [<https://redis.io/commands/config-set/>](https://redis.io/commands/config-set/)
#[must_use]
fn config_set<P, V, C>(self, configs: C) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
P: SingleArg,
V: SingleArg,
C: KeyValueArgsCollection<P, V>,
{
prepare_command(self, cmd("CONFIG").arg("SET").arg(configs))
}
/// Return the number of keys in the currently-selected database.
///
/// # See Also
/// [<https://redis.io/commands/dbsize/>](https://redis.io/commands/dbsize/)
#[must_use]
fn dbsize(self) -> PreparedCommand<'a, Self, usize>
where
Self: Sized,
{
prepare_command(self, cmd("DBSIZE"))
}
/// This command will start a coordinated failover between
/// the currently-connected-to master and one of its replicas.
///
/// # See Also
/// [<https://redis.io/commands/failover/>](https://redis.io/commands/failover/)
#[must_use]
fn failover(self, options: FailOverOptions) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
{
prepare_command(self, cmd("FAILOVER").arg(options))
}
/// Delete all the keys of the currently selected DB.
///
/// # See Also
/// [<https://redis.io/commands/flushdb/>](https://redis.io/commands/flushdb/)
#[must_use]
fn flushdb(self, flushing_mode: FlushingMode) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
{
prepare_command(self, cmd("FLUSHDB").arg(flushing_mode))
}
/// Delete all the keys of all the existing databases, not just the currently selected one.
///
/// # See Also
/// [<https://redis.io/commands/flushall/>](https://redis.io/commands/flushall/)
#[must_use]
fn flushall(self, flushing_mode: FlushingMode) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
{
prepare_command(self, cmd("FLUSHALL").arg(flushing_mode))
}
/// This command returns information and statistics about the server
/// in a format that is simple to parse by computers and easy to read by humans.
///
/// # See Also
/// [<https://redis.io/commands/info/>](https://redis.io/commands/info/)
#[must_use]
fn info<SS>(self, sections: SS) -> PreparedCommand<'a, Self, String>
where
Self: Sized,
SS: SingleArgCollection<InfoSection>,
{
prepare_command(self, cmd("INFO").arg(sections))
}
/// Return the UNIX TIME of the last DB save executed with success.
///
/// # See Also
/// [<https://redis.io/commands/lastsave/>](https://redis.io/commands/lastsave/)
#[must_use]
fn lastsave(self) -> PreparedCommand<'a, Self, u64>
where
Self: Sized,
{
prepare_command(self, cmd("LASTSAVE"))
}
/// This command reports about different latency-related issues and advises about possible remedies.
///
/// # Return
/// String report
///
/// # See Also
/// [<https://redis.io/commands/latency-doctor/>](https://redis.io/commands/latency-doctor/)
#[must_use]
fn latency_doctor(self) -> PreparedCommand<'a, Self, String>
where
Self: Sized,
{
prepare_command(self, cmd("LATENCY").arg("DOCTOR"))
}
/// Produces an ASCII-art style graph for the specified event.
///
/// # Return
/// String graph
///
/// # See Also
/// [<https://redis.io/commands/latency-graph/>](https://redis.io/commands/latency-graph/)
#[must_use]
fn latency_graph(self, event: LatencyHistoryEvent) -> PreparedCommand<'a, Self, String>
where
Self: Sized,
{
prepare_command(self, cmd("LATENCY").arg("GRAPH").arg(event))
}
/// The command returns a helpful text describing the different LATENCY subcommands.
///
/// # Return
/// An array of strings.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::ServerCommands,
/// # Result,
/// # };
/// #
/// # #[cfg_attr(feature = "tokio-runtime", tokio::main)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::main)]
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// let result: Vec<String> = client.latency_help().await?;
/// assert!(result.iter().any(|e| e == "HELP"));
/// # Ok(())
/// # }
/// ```
/// # See Also
/// [<https://redis.io/commands/latency-help/>](https://redis.io/commands/latency-help/)
fn latency_help(self) -> PreparedCommand<'a, Self, Vec<String>>
where
Self: Sized,
{
prepare_command(self, cmd("LATENCY").arg("HELP"))
}
/// This command reports a cumulative distribution of latencies
/// in the format of a histogram for each of the specified command names.
///
/// # Return
/// The command returns a map where each key is a command name, and each value is a CommandHistogram instance.
///
/// # See Also
/// [<https://redis.io/commands/latency-histogram/>](https://redis.io/commands/latency-histogram/)
#[must_use]
fn latency_histogram<C, CC, RR>(self, commands: CC) -> PreparedCommand<'a, Self, RR>
where
Self: Sized,
C: SingleArg,
CC: SingleArgCollection<C>,
RR: KeyValueCollectionResponse<String, CommandHistogram>,
{
prepare_command(self, cmd("LATENCY").arg("HISTOGRAM").arg(commands))
}
/// This command returns the raw data of the event's latency spikes time series.
///
/// # Return
/// The command returns a collection where each element is a two elements tuple representing
/// - the unix timestamp in seconds
/// - the latency of the event in milliseconds
///
/// # See Also
/// [<https://redis.io/commands/latency-history/>](https://redis.io/commands/latency-history/)
#[must_use]
fn latency_history<RR>(self, event: LatencyHistoryEvent) -> PreparedCommand<'a, Self, RR>
where
Self: Sized,
RR: CollectionResponse<(u32, u32)>,
{
prepare_command(self, cmd("LATENCY").arg("HISTORY").arg(event))
}
/// This command reports the latest latency events logged.
///
/// # Return
/// A collection of the latest latency events logged.
/// Each reported event has the following fields:
/// - Event name.
/// - Unix timestamp of the latest latency spike for the event.
/// - Latest event latency in millisecond.
/// - All-time maximum latency for this event.
///
/// "All-time" means the maximum latency since the Redis instance was started,
/// or the time that events were [`reset`](crate::commands::ConnectionCommands::reset).
///
/// # See Also
/// [<https://redis.io/commands/latency-latest/>](https://redis.io/commands/latency-latest/)
#[must_use]
fn latency_latest<RR>(self) -> PreparedCommand<'a, Self, RR>
where
Self: Sized,
RR: CollectionResponse<(String, u32, u32, u32)>,
{
prepare_command(self, cmd("LATENCY").arg("LATEST"))
}
/// This command resets the latency spikes time series of all, or only some, events.
///
/// # Return
/// the number of event time series that were reset.
///
/// # See Also
/// [<https://redis.io/commands/latency-latest/>](https://redis.io/commands/latency-latest/)
#[must_use]
fn latency_reset<EE>(self, events: EE) -> PreparedCommand<'a, Self, usize>
where
Self: Sized,
EE: SingleArgCollection<LatencyHistoryEvent>,
{
prepare_command(self, cmd("LATENCY").arg("RESET").arg(events))
}
/// The LOLWUT command displays the Redis version: however as a side effect of doing so,
/// it also creates a piece of generative computer art that is different with each version of Redis.
///
/// # Return
/// the string containing the generative computer art, and a text with the Redis version.
///
/// # See Also
/// [<https://redis.io/commands/lolwut/>](https://redis.io/commands/lolwut/)
#[must_use]
fn lolwut(self, options: LolWutOptions) -> PreparedCommand<'a, Self, String>
where
Self: Sized,
{
prepare_command(self, cmd("LOLWUT").arg(options))
}
/// This command reports about different memory-related issues that
/// the Redis server experiences, and advises about possible remedies.
///
/// # Return
/// the string report.
///
/// # See Also
/// [<https://redis.io/commands/memory-doctor/>](https://redis.io/commands/memory-doctor/)
#[must_use]
fn memory_doctor(self) -> PreparedCommand<'a, Self, String>
where
Self: Sized,
{
prepare_command(self, cmd("MEMORY").arg("DOCTOR"))
}
/// The command returns a helpful text describing the different MEMORY subcommands.
///
/// # Return
/// An array of strings.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::ServerCommands,
/// # Result,
/// # };
/// #
/// # #[cfg_attr(feature = "tokio-runtime", tokio::main)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::main)]
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// let result: Vec<String> = client.memory_help().await?;
/// assert!(result.iter().any(|e| e == "HELP"));
/// # Ok(())
/// # }
/// ```
///
/// # See Also
/// [<https://redis.io/commands/memory-help/>](https://redis.io/commands/memory-help/)
#[must_use]
fn memory_help(self) -> PreparedCommand<'a, Self, Vec<String>>
where
Self: Sized,
{
prepare_command(self, cmd("MEMORY").arg("HELP"))
}
/// This command provides an internal statistics report from the memory allocator.
///
/// # Return
/// the memory allocator's internal statistics report.
///
/// # See Also
/// [<https://redis.io/commands/memory-malloc-stats/>](https://redis.io/commands/memory-malloc-stats/)
#[must_use]
fn memory_malloc_stats(self) -> PreparedCommand<'a, Self, String>
where
Self: Sized,
{
prepare_command(self, cmd("MEMORY").arg("MALLOC-STATS"))
}
/// This command attempts to purge dirty pages so these can be reclaimed by the allocator.
///
/// # See Also
/// [<https://redis.io/commands/memory-purge/>](https://redis.io/commands/memory-purge/)
#[must_use]
fn memory_purge(self) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
{
prepare_command(self, cmd("MEMORY").arg("PURGE"))
}
/// This command returns information about the memory usage of the server.
///
/// # Return
/// the memory allocator's internal statistics report.
///
/// # See Also
/// [<https://redis.io/commands/memory-stats/>](https://redis.io/commands/memory-stats/)
#[must_use]
fn memory_stats(self) -> PreparedCommand<'a, Self, MemoryStats>
where
Self: Sized,
{
prepare_command(self, cmd("MEMORY").arg("STATS"))
}
/// This command reports the number of bytes that a key and its value require to be stored in RAM.
///
/// # Return
/// the memory usage in bytes, or None when the key does not exist.
///
/// # See Also
/// [<https://redis.io/commands/memory-usage/>](https://redis.io/commands/memory-usage/)
#[must_use]
fn memory_usage<K>(
self,
key: K,
options: MemoryUsageOptions,
) -> PreparedCommand<'a, Self, Option<usize>>
where
Self: Sized,
K: SingleArg,
{
prepare_command(self, cmd("MEMORY").arg("USAGE").arg(key).arg(options))
}
/// Returns information about the modules loaded to the server.
///
/// # Return
/// list of loaded modules.
/// Each element in the list represents a module as an instance of [`ModuleInfo`](ModuleInfo)
///
/// # See Also
/// [<https://redis.io/commands/module-list/>](https://redis.io/commands/module-list/)
#[must_use]
fn module_list<MM>(self) -> PreparedCommand<'a, Self, MM>
where
Self: Sized,
MM: CollectionResponse<ModuleInfo>,
{
prepare_command(self, cmd("MODULE").arg("LIST"))
}
/// The command returns a helpful text describing the different MODULE subcommands.
///
/// # Return
/// An array of strings.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::ServerCommands,
/// # Result,
/// # };
/// #
/// # #[cfg_attr(feature = "tokio-runtime", tokio::main)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::main)]
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// let result: Vec<String> = client.module_help().await?;