redis_event/cmd/
connection.rs

1/*!
2Connection相关的命令定义、解析
3
4所有涉及到的命令参考[Redis Command Reference]
5
6[Redis Command Reference]: https://redis.io/commands#connection
7*/
8
9use std::slice::Iter;
10
11#[derive(Debug)]
12pub struct SELECT {
13    pub db: i32,
14}
15
16pub(crate) fn parse_select(mut iter: Iter<Vec<u8>>) -> SELECT {
17    let db = String::from_utf8_lossy(iter.next().unwrap());
18    let db = db.parse::<i32>().unwrap();
19    SELECT { db }
20}
21
22#[derive(Debug)]
23pub struct SWAPDB<'a> {
24    pub index1: &'a [u8],
25    pub index2: &'a [u8],
26}
27
28pub(crate) fn parse_swapdb(mut iter: Iter<Vec<u8>>) -> SWAPDB {
29    let index1 = iter.next().unwrap();
30    let index2 = iter.next().unwrap();
31    SWAPDB { index1, index2 }
32}