33 lines
613 B
Rust
33 lines
613 B
Rust
|
use redis::{
|
||
|
Client,
|
||
|
Connection,
|
||
|
Commands
|
||
|
};
|
||
|
use ron::de::from_str;
|
||
|
|
||
|
pub type Line = Vec<(f32,f32,u32)>;
|
||
|
|
||
|
pub struct RedisCtrl {
|
||
|
pub client: Client,
|
||
|
pub connection: Connection
|
||
|
}
|
||
|
|
||
|
impl RedisCtrl {
|
||
|
|
||
|
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
||
|
let client = Client::open("redis://127.0.0.1/")?;
|
||
|
let connection = client.get_connection()?;
|
||
|
Ok(RedisCtrl { client, connection })
|
||
|
}
|
||
|
|
||
|
pub fn get(
|
||
|
&mut self,
|
||
|
key: &str
|
||
|
) -> Result<Line, Box<dyn std::error::Error>> {
|
||
|
let val : String = self.connection.get(key)?;
|
||
|
let line : Line = from_str(&val)?;
|
||
|
Ok(line)
|
||
|
}
|
||
|
}
|
||
|
|