lj_rust/src/redis_ctrl.rs

33 lines
613 B
Rust
Raw Normal View History

2023-06-03 13:21:36 +00:00
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)
}
}