An implementation of the redis protocol specification with an execution helper using
the TcpStream
provided by async-std.
use kramer::{Command, StringCommand, Arity, Insertion};
use std::env::{var};
use std::io::prelude::*;
fn get_redis_url() -> String {
let host = var("REDIS_HOST").unwrap_or(String::from("0.0.0.0"));
let port = var("REDIS_PORT").unwrap_or(String::from("6379"));
format!("{}:{}", host, port)
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = get_redis_url();
let cmd = Command::Keys::<_, &str>("*");
let mut stream = std::net::TcpStream::connect(url)?;
write!(stream, "{}", cmd)?;
write!(stream, "{}", StringCommand::Set(Arity::One(("name", "kramer")), None, Insertion::Always))?;
Ok(())
}