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
use crate::{
resp::Value, Command, CommandSend, ConnectionMultiplexer, GenericCommands, HashCommands,
ListCommands, Result, ScriptingCommands, ServerCommands, SetCommands, StringCommands,
Transaction,
};
use futures::Future;
use std::pin::Pin;
#[derive(Clone)]
pub struct Database {
multiplexer: ConnectionMultiplexer,
db: usize,
}
impl Database {
pub(crate) fn new(multiplexer: ConnectionMultiplexer, db: usize) -> Self {
Self { multiplexer, db }
}
pub fn get_database(&self) -> usize {
self.db
}
pub fn send<'a>(&'a self, command: Command) -> impl Future<Output = Result<Value>> + 'a {
self.multiplexer.send(self.db, command)
}
pub fn create_transaction(&self) -> Transaction {
Transaction::new(self.clone())
}
}
impl CommandSend for Database {
fn send(&self, command: Command) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + '_>> {
Box::pin(self.send(command))
}
}
impl GenericCommands for Database {}
impl HashCommands for Database {}
impl ListCommands for Database {}
impl ScriptingCommands for Database {}
impl ServerCommands for Database {}
impl SetCommands for Database {}
impl StringCommands for Database {}