#![allow(clippy::unnecessary_fallible_conversions)]
#![allow(clippy::redundant_pattern_matching)]
#![allow(clippy::mutable_key_type)]
#![allow(clippy::derivable_impls)]
#![allow(clippy::enum_variant_names)]
#![allow(clippy::iter_kv_map)]
#![allow(clippy::len_without_is_empty)]
#![allow(clippy::vec_init_then_push)]
#![allow(clippy::while_let_on_iterator)]
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::new_without_default)]
#![warn(clippy::large_types_passed_by_value)]
#![warn(clippy::large_stack_frames)]
#![warn(clippy::large_futures)]
#![cfg_attr(docsrs, deny(rustdoc::broken_intra_doc_links))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, allow(unused_attributes))]
#![doc = include_str!("../README.md")]
#[macro_use]
extern crate async_trait;
#[macro_use]
extern crate log;
pub extern crate bytes;
pub extern crate bytes_utils;
#[cfg(feature = "enable-native-tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "enable-native-tls")))]
pub extern crate native_tls;
#[cfg(feature = "enable-rustls")]
#[cfg_attr(docsrs, doc(cfg(feature = "enable-rustls")))]
pub extern crate rustls;
#[cfg(feature = "enable-rustls")]
#[cfg_attr(docsrs, doc(cfg(feature = "enable-rustls")))]
pub extern crate rustls_native_certs;
#[cfg(feature = "serde-json")]
pub extern crate serde_json;
pub extern crate socket2;
#[cfg(feature = "codec")]
#[cfg_attr(docsrs, doc(cfg(feature = "codec")))]
pub extern crate tokio_util;
#[cfg(feature = "partial-tracing")]
#[cfg_attr(docsrs, doc(cfg(feature = "partial-tracing")))]
pub extern crate tracing;
#[cfg(any(feature = "full-tracing", feature = "partial-tracing"))]
extern crate tracing_futures;
#[macro_use]
mod macros;
mod commands;
mod modules;
mod protocol;
mod router;
mod trace;
mod utils;
pub mod clients;
pub mod error;
pub mod interfaces;
#[cfg(feature = "mocks")]
#[cfg_attr(docsrs, doc(cfg(feature = "mocks")))]
pub use modules::mocks;
#[cfg(feature = "monitor")]
#[cfg_attr(docsrs, doc(cfg(feature = "monitor")))]
pub mod monitor;
pub mod types;
#[cfg(feature = "codec")]
#[cfg_attr(docsrs, doc(cfg(feature = "codec")))]
pub mod codec {
pub use super::protocol::public::*;
}
pub mod util {
pub use crate::utils::{f64_to_redis_string, redis_string_to_f64, static_bytes, static_str};
use crate::{error::RedisError, types::RedisKey};
pub use redis_protocol::redis_keyslot;
use std::collections::{BTreeMap, VecDeque};
pub const NONE: Option<String> = None;
#[cfg(feature = "sha-1")]
#[cfg_attr(docsrs, doc(cfg(feature = "sha-1")))]
pub fn sha1_hash(input: &str) -> String {
use sha1::Digest;
let mut hasher = sha1::Sha1::new();
hasher.update(input.as_bytes());
format!("{:x}", hasher.finalize())
}
pub fn group_by_hash_slot<T>(
args: impl IntoIterator<Item = T>,
) -> Result<BTreeMap<u16, VecDeque<RedisKey>>, RedisError>
where
T: TryInto<RedisKey>,
T::Error: Into<RedisError>,
{
let mut out = BTreeMap::new();
for arg in args.into_iter() {
let arg: RedisKey = to!(arg)?;
let slot = redis_keyslot(arg.as_bytes());
out.entry(slot).or_insert(VecDeque::new()).push_back(arg);
}
Ok(out)
}
}
pub mod prelude {
#[cfg(feature = "partial-tracing")]
#[cfg_attr(docsrs, doc(cfg(feature = "partial-tracing")))]
pub use crate::types::TracingConfig;
pub use crate::{
clients::{RedisClient, RedisPool},
error::{RedisError, RedisErrorKind},
interfaces::*,
types::{
Blocking,
Builder,
ConnectionConfig,
Expiration,
FromRedis,
Options,
PerformanceConfig,
ReconnectPolicy,
RedisConfig,
RedisKey,
RedisValue,
RedisValueKind,
Server,
ServerConfig,
SetOptions,
TcpConfig,
},
};
#[cfg(any(feature = "enable-native-tls", feature = "enable-rustls"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "enable-rustls", feature = "enable-native-tls"))))]
pub use crate::types::{TlsConfig, TlsConnector};
}