Expand description
rustis is a Redis client for Rust.
Philosophy
- Low allocations
- Full async library
- Lock free implementation
- Rust idiomatic API
Features
- Support all Redis Commands until Redis 7.0
- Async support (tokio or async-std)
- Different client types:
- Single client
- Multiplexed client
- Pooled client manager (based on bb8)
- Automatic command batching
- Pipelining support
- Configuration with Redis URL or dedicated builder
- TLS support
- Transaction support
- Pub/sub support
- Sentinel support
- LUA Scripts/Functions support
- Cluster support
- Redis Stack support:
- RedisJSON v2.4 support
- RedisSearch v2.6 support
- RedisGraph v2.10 support
- RedisBloom v2.4 support
- RedisTimeSeries v1.8 support
Optional Features
tokio-runtime
- Tokio runime (default)async-std-runtime
- async-std runtime (optional)tokio-tls
- Tokio TLS support (optional)async-std-tls
- async-std TLS support (optional)pool
- Pooled client manager (optional)redis-json
- RedisJSON v2.4 support (optional)redis-search
- RedisSearch v2.6 support (optional)redis-graph
- RedisGraph v2.10 support (optional)redis-bloom
- RedisBloom v2.4 support (optional)redis-time-series
- RedisTimeSeries v1.8 support (optional)redis-stack
- activateredis-json
,redis-search
,redis-graph
,redis-bloom
&redis-time-series
at the same time (optional)
Basic Usage
Client
The central object in rustis is the client. There are 3 kinds of clients.
The single client
The single Client
maintains a unique connection to a Redis Server or cluster and is not thread-safe.
use rustis::{
Client, FlushingMode,
Result, ServerCommands, StringCommands
};
#[tokio::main]
async fn main() -> Result<()> {
let mut client = Client::connect("127.0.0.1:6379").await?;
client.flushdb(FlushingMode::Sync).await?;
client.set("key", "value").await?;
let value: String = client.get("key").await?;
println!("value: {value:?}");
Ok(())
}
The multiplexed client
A multiplexed client can be cloned, allowing requests to be be sent concurrently on the same underlying connection.
Compared to a single client, a multiplexed client cannot offers access to all existing Redis commands. Transactions and blocking commands are not compatible with a multiplexed client because they monopolize the whole connection which cannot be shared anymore. It means other consumers of the same multiplexed client will be blocked each time a transaction or a blocking command is in progress, losing the advantage of a shared connection.
See also Multiplexing Explained
use rustis::{
FlushingMode, MultiplexedClient,
Result, ServerCommands, StringCommands
};
#[tokio::main]
async fn main() -> Result<()> {
let mut client1 = MultiplexedClient::connect("127.0.0.1:6379").await?;
client1.flushdb(FlushingMode::Sync).await?;
client1.set("key", "value").await?;
let value: String = client1.get("key").await?;
println!("value: {value:?}");
// clone a second instance on the same underlying connection
let mut client2 = client1.clone();
let value: String = client2.get("key").await?;
println!("value: {value:?}");
Ok(())
}
The pooled client manager
The pooled client manager holds a pool of client, based on bb8.
Each time a new command must be sent to the Redis Server, a client will be borrowed temporarily to the manager and automatic given back to it at the end of the operation.
The manager can be configured via bb8 with a various of options like maximum size, maximum lifetime, etc.
For you convenience, bb8 is reexport from the rustis crate.
use rustis::{
PooledClientManager, Result, StringCommands
};
#[tokio::main]
async fn main() -> Result<()> {
let manager = PooledClientManager::new("127.0.0.1:6379")?;
let pool = rustis::bb8::Pool::builder()
.max_size(10)
.build(manager).await?;
let mut client1 = pool.get().await.unwrap();
client1.set("key1", "value1").await?;
let value: String = client1.get("key1").await?;
println!("value: {value:?}");
let mut client2 = pool.get().await.unwrap();
client2.set("key2", "value2").await?;
let value: String = client2.get("key2").await?;
println!("value: {value:?}");
Ok(())
}
Re-exports
pub use bb8;
Modules
Structs
acl_cat
commandacl_dryrun
commandacl_genpass
commandacl_log
commandredis-bloom
bf_info
command.redis-bloom
bf_insert
command.redis-bloom
bf_reserve
command.redis-bloom
cf_info
command.redis-bloom
cf_insert
command.redis-bloom
cf_reserve
command.client_info
& client_list
commands.client-kill
command.client_list
command.client_trackinginfo
command.client_tracking
command.Cluster
cluster_info
commandcluster_links
commandcluster_shards
command.cluster_shards
command.redis-bloom
cms_info
command.command_docs
commandlatency_histogram
commands.command
command.command_list
command.client
or a multiplexed client
dump
command.failover
command.redis-search
ft_create
commandredis-search
ft_create
commandredis-search
ft_info
commandredis-search
ft_create
commandredis-search
redis-search
ft_info
commandredis-search
ft_info
commandredis-search
LOAD
aggregate optionredis-search
ft_spellcheck
command.redis-search
ft_profile
command.redis-search
ft_profile
command.redis-search
ft_aggregate
& ft_search
commandsredis-search
FtQueryResult
redis-search
ft_profile
command.redis-search
redis-search
ft_search
command.redis-search
redis-search
redis-search
ft_spellcheck
command.redis-search
ft_spellcheck
command.redis-search
ft_sugadd
command.redis-search
ft_sugget
command.redis-search
ft_sugget
command.redis-search
withcursor
aggregate optionfunction_list
commandgeosearch
commandgeosearch
command.geosearchstore
commandredis-graph
redis-graph
redis-graph
redis-graph
redis-graph
redis-graph
graph_query
commandredis-graph
redis-graph
redis-graph
graph_query
commandredis-graph
graph_slowlog
commandhscan
commandhello
command.redis-json
json_arrindex
commandredis-json
json_get
commandcommand
command.lolwut
commandmemory_stats
command.memory_usage
commandmodule_list
command.module_load
commandMONITOR
command events
when the stream is dropped or closed, a reset command is sent to the Redis serverping
command.pub_sub_channels
commandsubscribed
toreplicaof
command.restore
commandsscan
commandscan
commandSentinel
shutdown
command.slowlog_get
for the command.slowlog_get
command.sort
commandredis-bloom
tdigest_info
command.redis-bloom
tdigest_merge
command.redis-bloom
topk_info
command.transaction
on a specific client instance.redis-time-series
ts_add
command.redis-time-series
compaction rules
of a time series collection, in the context of the ts_info
command.redis-time-series
ts_add
command.redis-time-series
ts_createrule
command.redis-time-series
ts_get
command.redis-time-series
ts_mrange
command.redis-time-series
redis-time-series
ts_info
command.redis-time-series
ts_mget
command.redis-time-series
ts_mrange
and
ts_mrevrange
commands.redis-time-series
ts_range
and
ts_revrange
commands.xadd
command.xautoclaim
commandxclaim
commandxinfo_consumers
command.xgroup_create
commandxinfo_groups
command.xinfo_stream
commandxpending
commandxpending_with_options
commandxpending_with_options
commandxpending
commandxreadgroup
commandxread
commandxinfo_stream
command.zadd
command.zrange
and zrangestore
commandszscan
commandEnums
redis-bloom
bf_info
command.bitfield
commandbitop
command.client_caching
command.client_pause
command.client_reply
command.client_tracking
command.client_list
command.client_unblock
command.cluster_bumpepoch
commandcluster_failover
commandcluster_shards
command.cluster reset
cluster_setslot
command.cluster_state
field of ClusterInfo
expire
commandredis-search
ft_create
commandredis-search
FtCreateOptions
structredis-search
Supported Languages
redis-search
FtFieldSchema::phonetic
methodredis-search
ft_profile
commandredis-search
terms
function_restore
command.geoadd
commandgetex
commandredis-graph
info
command.latency_graph
& latency_history
commands.migrate
commandrole
command.sentinel_simulate_failure
commandset_with_options
commandset_with_options
commandredis-time-series
ts_createrule
and ts_mrange
commands.redis-time-series
Policy
for handling samples with identical timestampsredis-time-series
zadd
commandzadd
commandzrange
commandTraits
redis-bloom
Bloom filters
Cluster Management
redis-bloom
Count-min Sketch
redis-bloom
Cuckoo filters
redis-graph
Geospatial
indicesredis-graph
RedisGraph
Hashes
HyperLogLog
Config
conversion that consumes the input value. redis-json
RedisJson
Lists
Pub/Sub
redis-search
RedisSearch
Sets
Sorted Sets
Streams
Strings
redis-bloom
T-Digest
redis-time-series
Time Series
redis-bloom
Top-K