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
use crate::{
resp::Value, BitmapCommands, Command, CommandSend, ConnectionMultiplexer, Future,
GenericCommands, GeoCommands, HashCommands, ListCommands, Result, ScriptingCommands,
ServerCommands, SetCommands, SortedSetCommands, StringCommands, Transaction,
};
#[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 futures::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) -> Future<'_, Value> {
Box::pin(self.send(command))
}
}
impl BitmapCommands for Database {}
impl GenericCommands for Database {}
impl GeoCommands for Database {}
impl HashCommands for Database {}
impl ListCommands for Database {}
impl ScriptingCommands for Database {}
impl ServerCommands for Database {}
impl SetCommands for Database {}
impl SortedSetCommands for Database {}
impl StringCommands for Database {}