1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- use crate::{cmd, connection::Connection, dispatcher, error::Error, value::Value};
- use bytes::Bytes;
- use std::convert::TryInto;
- use std::time::SystemTime;
- use std::time::UNIX_EPOCH;
- fn do_time(_conn: &Connection, _args: &[Bytes]) -> Result<Value, Error> {
- let now = SystemTime::now();
- let since_the_epoch = now.duration_since(UNIX_EPOCH).expect("Time went backwards");
- let seconds = format!("{}", since_the_epoch.as_secs());
- let millis = format!("{}", since_the_epoch.subsec_millis());
- Ok(vec![seconds.as_str(), millis.as_str()].into())
- }
- fn do_command(_conn: &Connection, _args: &[Bytes]) -> Result<Value, Error> {
- let now = SystemTime::now();
- let since_the_epoch = now.duration_since(UNIX_EPOCH).expect("Time went backwards");
- let in_ms: i128 =
- since_the_epoch.as_secs() as i128 * 1000 + since_the_epoch.subsec_millis() as i128;
- Ok(format!("{}", in_ms).as_str().into())
- }
- dispatcher! {
- command {
- do_command,
- ["random" "loading" "stale"],
- 1,
- },
- client {
- cmd::client::client,
- ["random" "loading" "stale"],
- -2,
- },
- decr {
- cmd::string::decr,
- ["write" "denyoom" "fast"],
- 2,
- },
- echo {
- cmd::client::echo,
- ["random" "loading" "stale"],
- 2,
- },
- get {
- cmd::string::get,
- ["random" "loading" "stale"],
- 2,
- },
- incr {
- cmd::string::incr,
- ["write" "denyoom" "fast"],
- 2,
- },
- incrby {
- cmd::string::incr_by,
- ["write" "denyoom" "fast"],
- 3,
- },
- set {
- cmd::string::set,
- ["random" "loading" "stale"],
- -3,
- },
- getset {
- cmd::string::getset,
- ["random" "loading" "stale"],
- -3,
- },
- ping {
- cmd::client::ping,
- ["random" "loading" "stale"],
- -1,
- },
- time {
- do_time,
- ["random" "loading" "stale"],
- 1,
- },
- }
|