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
use crate::{
resp::{cmd, CommandArgs, IntoArgs},
CommandResult, PrepareCommand,
};
/// A group of Redis commands related to Server Management
/// # See Also
/// [Redis Server Management Commands](https://redis.io/commands/?group=server)
pub trait ServerCommands<T>: PrepareCommand<T> {
/// 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) -> CommandResult<T, ()> {
self.prepare_command(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) -> CommandResult<T, ()> {
self.prepare_command(cmd("FLUSHALL").arg(flushing_mode))
}
/// The TIME command returns the current server time as a two items lists:
/// a Unix timestamp and the amount of microseconds already elapsed in the current second.
///
/// # See Also
/// [https://redis.io/commands/time/](https://redis.io/commands/time/)
#[must_use]
fn time(&self) -> CommandResult<T, (u32, u32)> {
self.prepare_command(cmd("TIME"))
}
}
/// Database flushing mode
pub enum FlushingMode {
Default,
/// Flushes the database(s) asynchronously
Async,
/// Flushed the database(s) synchronously
Sync,
}
impl Default for FlushingMode {
fn default() -> Self {
FlushingMode::Default
}
}
impl IntoArgs for FlushingMode {
fn into_args(self, args: CommandArgs) -> CommandArgs {
match self {
FlushingMode::Default => args,
FlushingMode::Async => args.arg("ASYNC"),
FlushingMode::Sync => args.arg("SYNC"),
}
}
}