Crate rustis

source ·
Expand description

rustis is a Redis client for Rust.

Philosophy

  • Low allocations
  • Full async library
  • Lock free implementation
  • Rust idiomatic API

Features

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 - activate redis-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

Defines types related to the RESP protocol and their encoding/decoding

Structs

Options for the acl_cat command
Options for the acl_dryrun command
Options for the acl_genpass command
Options for the acl_log command
BfInfoResultredis-bloom
Result for the bf_info command.
BfInsertOptionsredis-bloom
Options for the bf_insert command.
BfReserveOptionsredis-bloom
Options for the bf_reserve command.
Interval options for the bitcount command
Builder for calling a script/function for the following commands:
CfInfoResultredis-bloom
Result for the cf_info command.
CfInsertOptionsredis-bloom
Options for the cf_insert command.
CfReserveOptionsredis-bloom
Options for the cf_reserve command.
Client with a unique connection to a Redis server.
Client info results for the client_info & client_list commands.
Options for the client-kill command.
Options for the client_list command.
Result for the client_list command.
Options for the client_tracking command.
Configuration for connecting to a Redis Cluster
Result for the cluster_info command
Result for the cluster_links command
Cluster node result for the cluster_shards command.
Result for the cluster_shards command.
CmsInfoResultredis-bloom
Result for the cms_info command.
Command doc result for the command_docs command
Command Histogram for the latency_histogram commands.
Command info result for the command command.
Options for the command_list command.
Configuration options for a client or a multiplexed client
Result for the dump command.
Options for the failover command.
FtAggregateOptionsredis-search
Options for the ft_create command
FtCreateOptionsredis-search
Options for the ft_create command
FtCursorStatsredis-search
Cursor stats for the ft_info command
FtFieldSchemaredis-search
field schema for the ft_create command
FtGcStatsredis-search
Garbage collector stats for the ft_info command
FtIndexAttributeredis-search
Index attribute info
FtIndexDefinitionredis-search
Index definitin for the ft_info command
FtInfoResultredis-search
Result for the ft_info command
FtLoadAttributeredis-search
Attribute for the LOAD aggregate option
FtMisspelledTermredis-search
Misspelled term + suggestions for the ft_spellcheck command.
FtProfileDetailsredis-search
Details of a ft_profile command.
FtProfileResultredis-search
Result for the ft_profile command.
FtQueryResultredis-search
Result for the ft_aggregate & ft_search commands
FtQueryResultRowredis-search
A row in a FtQueryResult
FtReducerredis-search
Reducer for the groupby aggregate option
Result processors profile for the ft_profile command.
sub-options for the search option summarize
FtSearchOptionsredis-search
Options for the ft_search command.
attribute for the search option return
sub-options for the search option summarize
FtSortByredis-search
option for the sortby aggregate option
Options for the ft_spellcheck command.
FtSpellCheckResultredis-search
Result for the ft_spellcheck command.
FtSugAddOptionsredis-search
Options for the ft_sugadd command.
FtSugGetOptionsredis-search
Options for the ft_sugget command.
FtSuggestionredis-search
Sugestion for the ft_sugget command.
options for the withcursor aggregate option
Options for the function_list command
Options for the geosearch command
Result of the geosearch command.
Options for the geosearchstore command
GraphEdgeredis-graph
Edges (or Relationships) are persistent graph elements that connect one node to another.
GraphHeaderredis-graph
Header part of a graph ’result set`
GraphNoderedis-graph
Nodes are persistent graph elements that can be connected to each other via relationships.
GraphPathredis-graph
Paths are alternating sequences of nodes and edges, starting and ending with a node.
GraphPropertiesredis-graph
Properties for a Node or an Edge
Options for the graph_query command
Statistics part of a graph ’result set`
GraphResultRowredis-graph
GraphResultSetredis-graph
Result set for the graph_query command
Result for the graph_slowlog command
Options for the hscan command
Options for the hello command.
Options for the json_arrindex command
JsonGetOptionsredis-json
Options for the json_get command
Key specifications of a command for the command command.
Result for the lcs command
Options for the lolwut command
Result for the memory_stats command.
Options for the memory_usage command
Module information result for the module_list command.
Options for the module_load command
Stream to get MONITOR command events when the stream is dropped or closed, a reset command is sent to the Redis server
A multiplexed client that can be cloned, allowing requests to be be sent concurrently on the same underlying connection.
Options for the ping command.
An object which manages a pool of clients, based on bb8
Stream to get messages from the channels or patterns subscribed to
Error issued by the Redis server
Represents a connected replicas to a master
options for the replicaof command.
Options for the restore command
Options for the sscan command
Options for the scan command
Configuration for connecting to a Redis server via Sentinel
options for the shutdown command.
Result slowlog_get for the command.
options for the slowlog_get command.
Options for the sort command
Result for the tdigest_info command.
Options for the tdigest_merge command.
Config for TLS.
TopKInfoResultredis-bloom
Result for the topk_info command.
Represents an on-going transaction on a specific client instance.
TsAddOptionsredis-time-series
Options for the ts_add command.
TsCompactionRuleredis-time-series
information about the compaction rules of a time series collection, in the context of the ts_info command.
TsCreateOptionsredis-time-series
Options for the ts_add command.
TsCreateRuleOptionsredis-time-series
Options for the ts_createrule command.
TsGetOptionsredis-time-series
Options for the ts_get command.
TsGroupByOptionsredis-time-series
Options for the ts_mrange command.
TsIncrByDecrByOptionsredis-time-series
Options for the ts_incrby and ts_decrby commands.
TsInfoResultredis-time-series
Result for the ts_info command.
TsMGetOptionsredis-time-series
Options for the ts_mget command.
TsMRangeOptionsredis-time-series
Options for the ts_mrange and ts_mrevrange commands.
TsRangeOptionsredis-time-series
Options for the ts_range and ts_revrange commands.
TsSampleredis-time-series
Result for the ts_mget command.
Stream Add options for the xadd command.
Options for the xautoclaim command
Options for the xclaim command
Result entry for the xinfo_consumers command.
Options for the xgroup_create command
Result entry for the xinfo_groups command.
Options for the xinfo_stream command
Customer info result for the xpending command
Message result for the xpending_with_options command
Options for the xpending_with_options command
Result for the xpending command
Options for the xreadgroup command
Options for the xread command
Stream info returned by the xinfo_stream command.
Stream Trim options for the xadd and xtrim commands
Options for the zadd command.
Options for the zrange and zrangestore commands
Options for the zscan command

Enums

Flag for a command argument
BfInfoParameterredis-bloom
Optional parameter for the bf_info command.
Sub-command for the bitfield command
Bit operation for the bitop command.
Client caching mode for the client_caching command.
Mode options for the client_pause command.
Mode options for the client_reply command.
Status options for the client_tracking command.
Client type options for the client_list command.
Mode options for the client_unblock command.
Cluster health status for the cluster_shards command.
This link is established by the local node to the peer, or accepted by the local node from the peer.
Subcommand for the cluster_setslot command.
Cluster state used in the cluster_state field of ClusterInfo
An argument must have one of the following types:
Command documenation flag
Get additional information about a command
All error kinds
Options for the expire command
Database flushing mode
FtFieldTyperedis-search
Field type used to declare an index schema for the ft_create command
FtIndexDataTyperedis-search
Redis Data type of an index defined in FtCreateOptions struct
FtLanguageredis-search
Redis search supported languages See. Supported Languages
FtPhoneticMatcherredis-search
Phonetic algorithm and language used for the FtFieldSchema::phonetic method
FtProfileQueryTyperedis-search
Type of query for the ft_profile command
FtTermTyperedis-search
Term type for the option terms
Policy option for the function_restore command.
Condition for the geoadd command
The query’s shape is provided by one of these mandatory options:
The query’s center point is provided by one of these mandatory options:
Matching items are returned unsorted by default. To sort them, use one of the following two options:
Distance Unit
Options for the getex command
GraphValueredis-graph
Section for the info command.
Latency history event for the latency_graph & latency_history commands.
Result for the migrate command
Redis server error kind
The state of the replication from the point of view of the master,
This tip can help clients determine the shards to send the command in clustering mode.
This tip can help clients determine the aggregate they need to compute from the replies of multiple shards in a cluster.
Result for the role command.
Different crash simulation scenario modes for the sentinel_simulate_failure command
Configuration for connecting to a Redis server
Condition option for the set_with_options command
Expiration option for the set_with_options command
Order option of the sort command
TsAggregationTyperedis-time-series
Aggregation type for the ts_createrule and ts_mrange commands.
TsDuplicatePolicyredis-time-series
Policy for handling samples with identical timestamps
TsEncodingredis-time-series
specifies the series samples encoding format.
Stream Trim operator for the xadd and xtrim commands
Comparison option for the zadd command
Condition option for the zadd command
Option that specify how results of an union or intersection are aggregated
sort by option of the zrange command
Where option of the zmpop command

Traits

A group of Redis commands related to Bitmaps & Bitfields
A group of blocking commands
BloomCommandsredis-bloom
A group of Redis commands related to Bloom filters
A group of Redis commands related to Cluster Management
A group of Redis commands related to connection management
A group of Redis commands related to Count-min Sketch
CuckooCommandsredis-bloom
A group of Redis commands related to Cuckoo filters
FromGraphValueredis-graph
A group of generic Redis commands
A group of Redis commands related to Geospatial indices
GraphCommandsredis-graph
A group of Redis commands related to RedisGraph
A group of Redis commands related to Hashes
A group of Redis commands related to HyperLogLog
A value-to-Config conversion that consumes the input value.
JsonCommandsredis-json
A group of Redis commands related to RedisJson
A group of Redis commands related to Lists
A group of Redis commands related to Pub/Sub
A group of Redis commands related to Scripting and Functions
SearchCommandsredis-search
A group of Redis commands related to RedisSearch
A group of Redis commands related to Sentinel
A group of Redis commands related to Server Management
A group of Redis commands related to Sets
A group of Redis commands related to Sorted Sets
A group of Redis commands related to Streams
A group of Redis commands related to Strings
TDigestCommandsredis-bloom
A group of Redis commands related to T-Digest
TimeSeriesCommandsredis-time-series
A group of Redis commands related to Time Series
TopKCommandsredis-bloom
A group of Redis commands related to Top-K
A group of Redis commands related to Transactions

Type Definitions

Library general future type.
Library general result type.