pub struct DatabaseRef { /* private fields */ }Expand description
A handle to a Database that can read and write, made by
Database::write. Copy, and free to pass to other code.
Implementations§
Source§impl DatabaseRef
impl DatabaseRef
Sourcepub fn generic(&self) -> Commands<'static>
pub fn generic(&self) -> Commands<'static>
Commands that work on a key of any type: expiry, deletion, renaming.
Sourcepub fn hash(&self) -> Commands<'static>
pub fn hash(&self) -> Commands<'static>
Commands on hashes: a key holding fields, each with a value.
Sourcepub fn sorted_set(&self) -> Commands<'static>
pub fn sorted_set(&self) -> Commands<'static>
Commands on sorted sets: members ordered by a score.
Sourcepub fn hyperloglog(&self) -> Commands<'static>
pub fn hyperloglog(&self) -> Commands<'static>
Commands on HyperLogLogs: estimates of how many distinct elements were added.
Sourcepub fn pipeline(&self) -> Pipeline<'static>
pub fn pipeline(&self) -> Pipeline<'static>
A batch of commands sent in one round trip. Not a transaction: other clients’ commands may run between them, and one failing does not stop the rest.
let mut pipe = SESSIONS.pipeline();
pipe.string().get("name:1");
pipe.string().get("name:2");
let (first, second): (Option<String>, Option<String>) = pipe.exec().await?;Sourcepub fn transaction(&self) -> Transaction<'static>
pub fn transaction(&self) -> Transaction<'static>
A transaction (MULTI/EXEC): the commands queued on it run
together, with no other client’s in between, or not at all.
Nothing is sent until Transaction::exec, so a transaction is
never left open across an .await.
let mut tx = LEDGER.transaction();
tx.string().incr("hits", 1);
tx.hash().hset("user:1", "seen", now);
let (hits, _): (i64, u64) = tx.exec().await?;Sourcepub async fn acquire(&self) -> Result<Connection, Error>
pub async fn acquire(&self) -> Result<Connection, Error>
Takes a connection out of the pool, for what must run on one connection: watching keys, then a transaction that depends on them. It is returned to the pool when dropped.
Sourcepub async fn watch<T>(
&self,
keys: impl ToRedisArgs,
body: impl AsyncFnMut(&Connection, &mut WatchedTransaction<'_>) -> Result<T, Error>,
) -> Result<T, Error>
pub async fn watch<T>( &self, keys: impl ToRedisArgs, body: impl AsyncFnMut(&Connection, &mut WatchedTransaction<'_>) -> Result<T, Error>, ) -> Result<T, Error>
Runs body as an optimistic transaction on keys: it reads what
it needs through the connection, queues its changes on the
transaction, and the changes are applied only if none of keys
changed in between. If one did, body runs again.
let left: i64 = LEDGER
.watch("balance", async |conn, tx| {
let balance: i64 = conn.string().get("balance").await?;
tx.string().set("balance", balance - 10);
Ok(balance - 10)
})
.await?;Sourcepub fn script(&self, script: &'static Script) -> Invocation<'static>
pub fn script(&self, script: &'static Script) -> Invocation<'static>
A call to script, to give its keys and arguments and then
Invocation::invoke.
Sourcepub fn command(&self, name: &'static str) -> CommandInvocation<'static>
pub fn command(&self, name: &'static str) -> CommandInvocation<'static>
A command the groups lack, by its name ("OBJECT"), which must be
a string literal: give its arguments in order with
CommandInvocation::key and CommandInvocation::arg, then
CommandInvocation::invoke. See the module docs
for what is checked before it is sent.
Sourcepub fn connection_string(&self) -> Result<String, Error>
pub fn connection_string(&self) -> Result<String, Error>
The connection string to connect to this database with, for a client other than this SDK’s.
It connects past the database’s key prefix (see the module docs): what that client stores under a name is not what this SDK reads under it.
Trait Implementations§
Source§impl Clone for DatabaseRef
impl Clone for DatabaseRef
impl Copy for DatabaseRef
Auto Trait Implementations§
impl !RefUnwindSafe for DatabaseRef
impl !UnwindSafe for DatabaseRef
impl Forget for DatabaseRef
impl Freeze for DatabaseRef
impl Move for DatabaseRef
impl Send for DatabaseRef
impl Sync for DatabaseRef
impl Unpin for DatabaseRef
impl UnsafeUnpin for DatabaseRef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request