Trait redis_driver::StringCommands
source · [−]pub trait StringCommands {
Show 22 methods
fn append<'life0, 'async_trait, K, V>(
&'life0 self,
key: K,
value: V
) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn decr<'life0, 'async_trait, K>(
&'life0 self,
key: K
) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
K: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn decrby<'life0, 'async_trait, K>(
&'life0 self,
key: K,
decrement: i64
) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
K: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn get<'life0, 'async_trait, K, V>(
&'life0 self,
key: K
) -> Pin<Box<dyn Future<Output = Result<V>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: FromValue,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn getdel<'life0, 'async_trait, K, V>(
&'life0 self,
key: K
) -> Pin<Box<dyn Future<Output = Result<V>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: FromValue,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn getex<K>(&self, key: K) -> GetEx<'_>
where
K: Into<BulkString> + Send;
fn getrange<'life0, 'async_trait, K, V>(
&'life0 self,
key: K,
start: usize,
end: isize
) -> Pin<Box<dyn Future<Output = Result<V>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: FromValue,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn getset<'life0, 'async_trait, K, V, R>(
&'life0 self,
key: K,
value: V
) -> Pin<Box<dyn Future<Output = Result<R>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
R: FromValue,
K: 'async_trait,
V: 'async_trait,
R: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn incr<'life0, 'async_trait, K>(
&'life0 self,
key: K
) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
K: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn incrby<'life0, 'async_trait, K>(
&'life0 self,
key: K,
increment: i64
) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
K: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn incrbyfloat<'life0, 'async_trait, K>(
&'life0 self,
key: K,
increment: f64
) -> Pin<Box<dyn Future<Output = Result<f64>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
K: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn lcs<K>(&self, key1: K, key2: K) -> Lcs<'_>
where
K: Into<BulkString> + Send;
fn mget<'a, 'async_trait, K, V>(
&'a self,
keys: K
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<V>>>> + Send + 'async_trait>>
where
K: IntoArgs + Send + Sync,
V: FromValue,
'a: 'async_trait,
K: 'async_trait,
V: 'async_trait,
Self: 'async_trait;
fn mset<'a, 'async_trait, K, V>(
&'a self,
items: &'a [(K, V)]
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send + Sync + Copy,
V: Into<BulkString> + Send + Sync + Copy,
'a: 'async_trait,
K: 'async_trait,
V: 'async_trait,
Self: 'async_trait;
fn msetnx<'a, 'async_trait, K, V>(
&'a self,
items: &'a [(K, V)]
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send + Sync + Copy,
V: Into<BulkString> + Send + Sync + Copy,
'a: 'async_trait,
K: 'async_trait,
V: 'async_trait,
Self: 'async_trait;
fn psetex<'life0, 'async_trait, K, V>(
&'life0 self,
key: K,
milliseconds: u64,
value: V
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn set<'life0, 'async_trait, K, V>(
&'life0 self,
key: K,
value: V
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn set_with_options<K, V>(&self, key: K, value: V) -> SetWithOptions<'_>
where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send;
fn setex<'life0, 'async_trait, K, V>(
&'life0 self,
key: K,
seconds: u64,
value: V
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn setnx<'life0, 'async_trait, K, V>(
&'life0 self,
key: K,
value: V
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn setrange<'life0, 'async_trait, K, V>(
&'life0 self,
key: K,
offset: usize,
value: V
) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
fn strlen<'life0, 'async_trait, K>(
&'life0 self,
key: K
) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where
K: Into<BulkString> + Send,
K: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait;
}
Expand description
Required Methods
Decrements the number stored at key by one.
If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.
Return
the value of key after the decrement
See Also
Decrements the number stored at key by one.
If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.
Return
the value of key after the decrement
See Also
Get the value of key.
Decrements the number stored at key by decrement. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.
Return
the value of key, or nil when key does not exist.
See Also
Get the value of key and optionally set its expiration. GETEX is similar to GET, but is a write command with additional options.
Decrements the number stored at key by decrement. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.
Return
the value of key, or nil when key does not exist.
Example
let connection = redis::ConnectionMultiplexer::connect("127.0.0.1:6379").await?;
let database = connection.get_default_database();
let value: String = database.getex("key").ex(60).await?;
See Also
Returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive).
Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last character, -2 the penultimate and so forth.
The function handles out of range requests by limiting the resulting range to the actual length of the string.
See Also
sourcefn getset<'life0, 'async_trait, K, V, R>(
&'life0 self,
key: K,
value: V
) -> Pin<Box<dyn Future<Output = Result<R>> + Send + 'async_trait>> where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
R: FromValue,
K: 'async_trait,
V: 'async_trait,
R: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn getset<'life0, 'async_trait, K, V, R>(
&'life0 self,
key: K,
value: V
) -> Pin<Box<dyn Future<Output = Result<R>> + Send + 'async_trait>> where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
R: FromValue,
K: 'async_trait,
V: 'async_trait,
R: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Atomically sets key to value and returns the old value stored at key. Returns an error when key exists but does not hold a string value. Any previous time to live associated with the key is discarded on successful SET operation.
Return
the old value stored at key, or nil when key did not exist.
See Also
Increments the number stored at key by one.
If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.
Note: this is a string operation because Redis does not have a dedicated integer type. The string stored at the key is interpreted as a base-10 64 bit signed integer to execute the operation.
Redis stores integers in their integer representation, so for string values that actually hold an integer, there is no overhead for storing the string representation of the integer.
Return
the value of key after the increment
See Also
Increments the number stored at key by increment.
If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.
See incr for extra information on increment/decrement operations.
Return
the value of key after the increment
See Also
Increment the string representing a floating point number stored at key by the specified increment. By using a negative increment value, the result is that the value stored at the key is decremented (by the obvious properties of addition). If the key does not exist, it is set to 0 before performing the operation. An error is returned if one of the following conditions occur:
-
The key contains a value of the wrong type (not a string).
-
The current key content or the specified increment are not parsable as a double precision floating point number.
If the command is successful the new incremented value is stored as the new value of the key (replacing the old one), and returned to the caller as a string.
Both the value already contained in the string key and the increment argument can be optionally provided in exponential notation, however the value computed after the increment is stored consistently in the same format, that is, an integer number followed (if needed) by a dot, and a variable number of digits representing the decimal part of the number. Trailing zeroes are always removed.
The precision of the output is fixed at 17 digits after the decimal point regardless of the actual internal precision of the computation.
Return
the value of key after the increment
See Also
The LCS command implements the longest common subsequence algorithm
See Also
sourcefn msetnx<'a, 'async_trait, K, V>(
&'a self,
items: &'a [(K, V)]
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where
K: Into<BulkString> + Send + Sync + Copy,
V: Into<BulkString> + Send + Sync + Copy,
'a: 'async_trait,
K: 'async_trait,
V: 'async_trait,
Self: 'async_trait,
fn msetnx<'a, 'async_trait, K, V>(
&'a self,
items: &'a [(K, V)]
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where
K: Into<BulkString> + Send + Sync + Copy,
V: Into<BulkString> + Send + Sync + Copy,
'a: 'async_trait,
K: 'async_trait,
V: 'async_trait,
Self: 'async_trait,
Sets the given keys to their respective values. MSETNX will not perform any operation at all even if just a single key already exists.
Because of this semantic MSETNX can be used in order to set different keys representing different fields of a unique logic object in a way that ensures that either all the fields or none at all are set.
MSETNX is atomic, so all given keys are set at once. It is not possible for clients to see that some of the keys were updated while others are unchanged.
Return
specifically:
- 1 if the all the keys were set.
- 0 if no key was set (at least one key already existed).
See Also
sourcefn psetex<'life0, 'async_trait, K, V>(
&'life0 self,
key: K,
milliseconds: u64,
value: V
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn psetex<'life0, 'async_trait, K, V>(
&'life0 self,
key: K,
milliseconds: u64,
value: V
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
K: 'async_trait,
V: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Set key to hold the string value.
If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.
See Also
sourcefn set_with_options<K, V>(&self, key: K, value: V) -> SetWithOptions<'_> where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
fn set_with_options<K, V>(&self, key: K, value: V) -> SetWithOptions<'_> where
K: Into<BulkString> + Send,
V: Into<BulkString> + Send,
Set key to hold the string value.
If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.
See Also
Set key to hold the string value and set key to timeout after a given number of seconds.