redis-asio
redis-asio is a Redis client library written in pure Rust based on
asynchronous tokio
library.
The library provides a base
module for low-level request sending and
response handling, and a stream
module that contains specific interfaces
for work with Redis-Stream "https://redis.io/topics/streams-intro".
The library works with binary-safe strings that allows users to serialize their message structures and send via RESP protocol "https://redis.io/topics/protocol".
Use in project
Depend on the redis-asio in project via Cargo:
[]
= "0.1"
Resolve the crate interfaces:
extern crate redis_asio;
Motivating examples
SET, GET value from cache
use SocketAddr;
use Future;
use ;
let address = &"127.0.0.1:6379"..unwrap;
let set_req = command.arg.arg;
let get_req = command.arg;
let future = connect
.and_then
.and_then
.map
.map_err;
// start the Tokio runtime using the `future`
run;
Subscribe to a Redis Stream
Subscribe to a Redis stream and process all incoming entries. Redis Streams requires to send XREAD/XREADGROUP requests every time the client receives a response on the previous, in other words Redis Streams does not provide an interface to subscribe to a Redis stream.
In the Crate the subscription is possible by hidden requests sending within the Crate engine.
Request that will be sent to get new entries in the following example: "XREADGROUP GROUP mygroup Bob BLOCK 0 STREAMS mystream <"
use SocketAddr;
use ;
use ;
let address = &"127.0.0.1:6379"..unwrap;
// create options to pass it into RedisStream::subscribe()
let group_info = new;
let subscribe_options =
with_group;
let future = connect
.and_then
.and_then
.map_err;
// start the Tokio runtime using the `future`
run;
Send an entry into a Redis Stream
Send an entry into a Redis stream. Request that will be sent to push a specified entry in the following example: "XADD mystream * type 3 data "Hello, world""
use SocketAddr;
use HashMap;
use Future;
use ;
use ;
let address = &"127.0.0.1:6379"..unwrap;
// create options to pass it into RedisStream::send_entry()
let send_options = new;
// create key-value pairs
let mut request: = new;
request.insert;
request.insert;
let future = connect
.and_then
.map
.map_err;
run;