pub trait StringCommands<'a> {
Show 25 methods
// Provided methods
fn append<K, V>(self, key: K, value: V) -> PreparedCommand<'a, Self, usize>
where Self: Sized,
K: SingleArg,
V: SingleArg { ... }
fn decr<K>(self, key: K) -> PreparedCommand<'a, Self, i64>
where Self: Sized,
K: SingleArg { ... }
fn decrby<K>(self, key: K, decrement: i64) -> PreparedCommand<'a, Self, i64>
where Self: Sized,
K: SingleArg { ... }
fn get<K, V>(self, key: K) -> PreparedCommand<'a, Self, V>
where Self: Sized,
K: SingleArg,
V: PrimitiveResponse { ... }
fn getdel<K, V>(self, key: K) -> PreparedCommand<'a, Self, V>
where Self: Sized,
K: SingleArg,
V: PrimitiveResponse { ... }
fn getex<K, V>(
self,
key: K,
options: GetExOptions,
) -> PreparedCommand<'a, Self, V>
where Self: Sized,
K: SingleArg,
V: PrimitiveResponse { ... }
fn getrange<K, V>(
self,
key: K,
start: usize,
end: isize,
) -> PreparedCommand<'a, Self, V>
where Self: Sized,
K: SingleArg,
V: PrimitiveResponse { ... }
fn getset<K, V, R>(self, key: K, value: V) -> PreparedCommand<'a, Self, R>
where Self: Sized,
K: SingleArg,
V: SingleArg,
R: PrimitiveResponse { ... }
fn incr<K>(self, key: K) -> PreparedCommand<'a, Self, i64>
where Self: Sized,
K: SingleArg { ... }
fn incrby<K>(self, key: K, increment: i64) -> PreparedCommand<'a, Self, i64>
where Self: Sized,
K: SingleArg { ... }
fn incrbyfloat<K>(
self,
key: K,
increment: f64,
) -> PreparedCommand<'a, Self, f64>
where Self: Sized,
K: SingleArg { ... }
fn lcs<K, V>(self, key1: K, key2: K) -> PreparedCommand<'a, Self, V>
where Self: Sized,
K: SingleArg,
V: PrimitiveResponse { ... }
fn lcs_len<K>(self, key1: K, key2: K) -> PreparedCommand<'a, Self, usize>
where Self: Sized,
K: SingleArg { ... }
fn lcs_idx<K>(
self,
key1: K,
key2: K,
min_match_len: Option<usize>,
with_match_len: bool,
) -> PreparedCommand<'a, Self, LcsResult>
where Self: Sized,
K: SingleArg { ... }
fn mget<K, KK, V, VV>(self, keys: KK) -> PreparedCommand<'a, Self, VV>
where Self: Sized,
K: SingleArg,
KK: SingleArgCollection<K>,
V: PrimitiveResponse + DeserializeOwned,
VV: CollectionResponse<V> { ... }
fn mset<K, V, C>(self, items: C) -> PreparedCommand<'a, Self, ()>
where Self: Sized,
C: KeyValueArgsCollection<K, V>,
K: SingleArg,
V: SingleArg { ... }
fn msetnx<K, V, C>(self, items: C) -> PreparedCommand<'a, Self, bool>
where Self: Sized,
C: KeyValueArgsCollection<K, V>,
K: SingleArg,
V: SingleArg { ... }
fn psetex<K, V>(
self,
key: K,
milliseconds: u64,
value: V,
) -> PreparedCommand<'a, Self, ()>
where Self: Sized,
K: SingleArg,
V: SingleArg { ... }
fn set<K, V>(self, key: K, value: V) -> PreparedCommand<'a, Self, ()>
where Self: Sized,
K: SingleArg,
V: SingleArg { ... }
fn set_with_options<K, V>(
self,
key: K,
value: V,
condition: SetCondition,
expiration: SetExpiration,
keep_ttl: bool,
) -> PreparedCommand<'a, Self, bool>
where Self: Sized,
K: SingleArg,
V: SingleArg { ... }
fn set_get_with_options<K, V1, V2>(
self,
key: K,
value: V1,
condition: SetCondition,
expiration: SetExpiration,
keep_ttl: bool,
) -> PreparedCommand<'a, Self, V2>
where Self: Sized,
K: SingleArg,
V1: SingleArg,
V2: PrimitiveResponse { ... }
fn setex<K, V>(
self,
key: K,
seconds: u64,
value: V,
) -> PreparedCommand<'a, Self, ()>
where Self: Sized,
K: SingleArg,
V: SingleArg { ... }
fn setnx<K, V>(self, key: K, value: V) -> PreparedCommand<'a, Self, bool>
where Self: Sized,
K: SingleArg,
V: SingleArg { ... }
fn setrange<K, V>(
self,
key: K,
offset: usize,
value: V,
) -> PreparedCommand<'a, Self, usize>
where Self: Sized,
K: SingleArg,
V: SingleArg { ... }
fn strlen<K>(self, key: K) -> PreparedCommand<'a, Self, usize>
where Self: Sized,
K: SingleArg { ... }
}
Expand description
Provided Methods§
Sourcefn append<K, V>(self, key: K, value: V) -> PreparedCommand<'a, Self, usize>
fn append<K, V>(self, key: K, value: V) -> PreparedCommand<'a, Self, usize>
Sourcefn decr<K>(self, key: K) -> PreparedCommand<'a, Self, i64>
fn decr<K>(self, key: K) -> PreparedCommand<'a, Self, i64>
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
Sourcefn decrby<K>(self, key: K, decrement: i64) -> PreparedCommand<'a, Self, i64>
fn decrby<K>(self, key: K, decrement: i64) -> PreparedCommand<'a, Self, i64>
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
Sourcefn get<K, V>(self, key: K) -> PreparedCommand<'a, Self, V>
fn get<K, V>(self, key: K) -> PreparedCommand<'a, Self, V>
Get the value of key.
Get the value of key. If the key does not exist the special value nil is returned. An error is returned if the value stored at key is not a string, because GET only handles string values.
§Return
the value of key, or nil
when key does not exist.
§Example
use rustis::{
client::{Client, ClientPreparedCommand},
commands::{FlushingMode, ServerCommands, StringCommands},
resp::{cmd},
Result
};
#[cfg_attr(feature = "tokio-runtime", tokio::main)]
#[cfg_attr(feature = "async-std-runtime", async_std::main)]
async fn main() -> Result<()> {
let client = Client::connect("127.0.0.1:6379").await?;
client.flushdb(FlushingMode::Sync).await?;
// return value can be an Option<String>...
let value: Option<String> = client.get("key").await?;
assert_eq!(None, value);
// ... or it can be directly a String.
// In this cas a `nil` value will result in an empty String
let value: String = client.get("key").await?;
assert_eq!("", &value);
client.set("key", "value").await?;
let value: String = client.get("key").await?;
assert_eq!("value", value);
Ok(())
}
§See Also
Sourcefn getdel<K, V>(self, key: K) -> PreparedCommand<'a, Self, V>
fn getdel<K, V>(self, key: K) -> PreparedCommand<'a, Self, V>
Get the value of key and delete the key.
This command is similar to GET, except for the fact that it also deletes the key on success (if and only if the key’s value type is a string).
§Return
the value of key, nil
when key does not exist, or an error if the key’s value type isn’t a string.
§See Also
Sourcefn getex<K, V>(
self,
key: K,
options: GetExOptions,
) -> PreparedCommand<'a, Self, V>
fn getex<K, V>( self, key: K, options: GetExOptions, ) -> PreparedCommand<'a, Self, V>
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
use rustis::{
client::{Client, ClientPreparedCommand},
commands::{FlushingMode, GetExOptions, GenericCommands, ServerCommands, StringCommands},
resp::cmd,
Result,
};
#[cfg_attr(feature = "tokio-runtime", tokio::main)]
#[cfg_attr(feature = "async-std-runtime", async_std::main)]
async fn main() -> Result<()> {
let client = Client::connect("127.0.0.1:6379").await?;
client.flushdb(FlushingMode::Sync).await?;
client.set("key", "value").await?;
let value: String = client.getex("key", GetExOptions::Ex(60)).await?;
assert_eq!("value", value);
let ttl = client.ttl("key").await?;
assert!(59 <= ttl && ttl <= 60);
Ok(())
}
§See Also
Sourcefn getrange<K, V>(
self,
key: K,
start: usize,
end: isize,
) -> PreparedCommand<'a, Self, V>
fn getrange<K, V>( self, key: K, start: usize, end: isize, ) -> PreparedCommand<'a, Self, V>
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<K, V, R>(self, key: K, value: V) -> PreparedCommand<'a, Self, R>
fn getset<K, V, R>(self, key: K, value: V) -> PreparedCommand<'a, Self, R>
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
Sourcefn incr<K>(self, key: K) -> PreparedCommand<'a, Self, i64>
fn incr<K>(self, key: K) -> PreparedCommand<'a, Self, i64>
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
Sourcefn incrby<K>(self, key: K, increment: i64) -> PreparedCommand<'a, Self, i64>
fn incrby<K>(self, key: K, increment: i64) -> PreparedCommand<'a, Self, i64>
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
Sourcefn incrbyfloat<K>(
self,
key: K,
increment: f64,
) -> PreparedCommand<'a, Self, f64>
fn incrbyfloat<K>( self, key: K, increment: f64, ) -> PreparedCommand<'a, Self, f64>
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
Sourcefn lcs<K, V>(self, key1: K, key2: K) -> PreparedCommand<'a, Self, V>
fn lcs<K, V>(self, key1: K, key2: K) -> PreparedCommand<'a, Self, V>
Sourcefn lcs_len<K>(self, key1: K, key2: K) -> PreparedCommand<'a, Self, usize>
fn lcs_len<K>(self, key1: K, key2: K) -> PreparedCommand<'a, Self, usize>
Sourcefn lcs_idx<K>(
self,
key1: K,
key2: K,
min_match_len: Option<usize>,
with_match_len: bool,
) -> PreparedCommand<'a, Self, LcsResult>
fn lcs_idx<K>( self, key1: K, key2: K, min_match_len: Option<usize>, with_match_len: bool, ) -> PreparedCommand<'a, Self, LcsResult>
Sourcefn mget<K, KK, V, VV>(self, keys: KK) -> PreparedCommand<'a, Self, VV>where
Self: Sized,
K: SingleArg,
KK: SingleArgCollection<K>,
V: PrimitiveResponse + DeserializeOwned,
VV: CollectionResponse<V>,
fn mget<K, KK, V, VV>(self, keys: KK) -> PreparedCommand<'a, Self, VV>where
Self: Sized,
K: SingleArg,
KK: SingleArgCollection<K>,
V: PrimitiveResponse + DeserializeOwned,
VV: CollectionResponse<V>,
Sourcefn mset<K, V, C>(self, items: C) -> PreparedCommand<'a, Self, ()>
fn mset<K, V, C>(self, items: C) -> PreparedCommand<'a, Self, ()>
Sourcefn msetnx<K, V, C>(self, items: C) -> PreparedCommand<'a, Self, bool>
fn msetnx<K, V, C>(self, items: C) -> PreparedCommand<'a, Self, bool>
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<K, V>(
self,
key: K,
milliseconds: u64,
value: V,
) -> PreparedCommand<'a, Self, ()>
fn psetex<K, V>( self, key: K, milliseconds: u64, value: V, ) -> PreparedCommand<'a, Self, ()>
Sourcefn set<K, V>(self, key: K, value: V) -> PreparedCommand<'a, Self, ()>
fn set<K, V>(self, key: K, value: V) -> PreparedCommand<'a, Self, ()>
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,
condition: SetCondition,
expiration: SetExpiration,
keep_ttl: bool,
) -> PreparedCommand<'a, Self, bool>
fn set_with_options<K, V>( self, key: K, value: V, condition: SetCondition, expiration: SetExpiration, keep_ttl: bool, ) -> PreparedCommand<'a, Self, bool>
Sourcefn set_get_with_options<K, V1, V2>(
self,
key: K,
value: V1,
condition: SetCondition,
expiration: SetExpiration,
keep_ttl: bool,
) -> PreparedCommand<'a, Self, V2>
fn set_get_with_options<K, V1, V2>( self, key: K, value: V1, condition: SetCondition, expiration: SetExpiration, keep_ttl: bool, ) -> PreparedCommand<'a, Self, V2>
Sourcefn setex<K, V>(
self,
key: K,
seconds: u64,
value: V,
) -> PreparedCommand<'a, Self, ()>
fn setex<K, V>( self, key: K, seconds: u64, value: V, ) -> PreparedCommand<'a, Self, ()>
Set key to hold the string value and set key to timeout after a given number of seconds.