Crate kramer

Source
Expand description

An implementation of the redis protocol specification with an execution helper using the TcpStream provided by async-std.

§Example

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(())
}

Enums§

Arity
The arity type here is used to mean a single or non-single container.
AuthCredentials
Redis authorization supports password and user/password authorization schemes.
Command
The main Command enum here represents all of the different variants of redis commands that are supported by the library.
HashCommand
HashCommand represents the possible redis operations of keys that are a hash type.
Insertion
Redis provides the ability to conditionally apply an inseration based on the existence of the a value that is equal.
ListCommand
Lists.
Response
Redis responses may either be an array of values, a single value, or an error.
ResponseLine
A response line is the type that is parsed from a single \r\n delimited string returned from the redis server.
ResponseValue
A redis response value may either be empty, a bulk string, or an integer.
SetCommand
The SetCommand is used for working with redis keys that are sets: unique collections of values.
Side
For lists, items can either be inserted on the left or right; this translates to whether or not the generated command is LPOP or RPOP (for example).
StringCommand
The StringCommand enum represents the most basic, key-value commands that redis offers; top-level keys with values being either strings or numbers.

Functions§

execute
Writes a command to the connection and will attempt to read a response.
humanize_command
By default, all commands will be formatted via the Display trait into the string representation that they would be sent over the wire as. This function should help users visualize commands in the format that they would issue them into the redis-cli as.
read
After sending a command, the read here is used to parse the response from our connection into the response enum.
send
This method will attempt to establish a new connection and execute the command.