pub struct Client { /* private fields */ }Expand description
The main client struct used to interact with the DiceDB server.
Create a new client with Client::new(host: String, port: u16).
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(host: String, port: u16) -> Result<Self, ClientError>
pub fn new(host: String, port: u16) -> Result<Self, ClientError>
Create a new client with the given host and port.
§Example
use dicedb_rs::client::Client;
use dicedb_rs::errors::ClientError;
fn main() -> Result<(), ClientError> {
// Create a new client
let client = Client::new("localhost".to_string(), 7379)?;
Ok(())
}§Errors
Returns a ClientError if the connection to the server fails.
Source§impl Client
impl Client
Sourcepub fn decr(&mut self, key: &str) -> Result<ScalarValue, StreamError>
pub fn decr(&mut self, key: &str) -> Result<ScalarValue, StreamError>
Decrements the integer at key by one. Creates key as -1 if absent. Errors on wrong type
or non-integer string. Limited to 64-bit signed integers.
§Arguments
key- The key to decrement.
§Returns
- [
Value] - The new value ofkey.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn decrby(
&mut self,
key: &str,
delta: i64,
) -> Result<ScalarValue, StreamError>
pub fn decrby( &mut self, key: &str, delta: i64, ) -> Result<ScalarValue, StreamError>
Decrements the integer at key by delta. Creates key as -delta if absent. Errors on
wrong type
or non-integer string. Limited to 64-bit signed integers.
§Arguments
key- The key to decrement.delta- The amount to decrement by.
§Returns
- [
Value] - The new value ofkey.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn del<'a, T: Into<DelInput<'a>>>(
&mut self,
keys: T,
) -> Result<ScalarValue, StreamError>
pub fn del<'a, T: Into<DelInput<'a>>>( &mut self, keys: T, ) -> Result<ScalarValue, StreamError>
Deletes all the specified keys and returns the number of keys deleted on success.
§Arguments
keys- The keys to delete, either a single key or multiple keys.
§Returns
- [
Value] - The number of keys deleted.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn echo(&mut self, message: &str) -> Result<ScalarValue, StreamError>
pub fn echo(&mut self, message: &str) -> Result<ScalarValue, StreamError>
Echos a message with the server, ie. returns the message passed to it.
§Arguments
message- The message to return.
§Returns
- [
Value] - The message.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn exists(
&mut self,
key: &str,
additional_keys: Vec<&str>,
) -> Result<ScalarValue, StreamError>
pub fn exists( &mut self, key: &str, additional_keys: Vec<&str>, ) -> Result<ScalarValue, StreamError>
Checks if the specified keys exist.
§Arguments
key- The key to check.additional_keys- Additional keys to check. If empty, onlykeyis checked.
§Returns
- [
Value] - The number of keys that exist.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn expire(
&mut self,
key: &str,
seconds: i64,
option: ExpireOption,
) -> Result<ScalarValue, StreamError>
pub fn expire( &mut self, key: &str, seconds: i64, option: ExpireOption, ) -> Result<ScalarValue, StreamError>
Sets an expiry (in seconds) on a specified key. After the expiry time has elapsed, the key will be automatically deleted.
§Arguments
key- The key to set the expiry on.seconds- The number of seconds until the key expires.option:ExpireOption- The option to specify conditions for setting the expiry.
§Returns
- [
Value] - 1 if the expiry was set, 0 if expire was not set.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn expireat(
&mut self,
key: &str,
timestamp: i64,
option: ExpireAtOption,
) -> Result<ScalarValue, StreamError>
pub fn expireat( &mut self, key: &str, timestamp: i64, option: ExpireAtOption, ) -> Result<ScalarValue, StreamError>
Sets the expiration time of a key as an absolute Unix timestamp (in seconds). After the expiry time has elapsed, the key will be automatically deleted.
§Arguments
key- The key to set the expiry on.timestamp- The Unix timestamp in seconds.option:ExpireAtOption- The option to specify conditions for setting the expiry.
§Returns
- [
Value] - 1 if the expiry was set or updated, 0 if the expiration time was not changed.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn expiretime(&mut self, key: &str) -> Result<ScalarValue, StreamError>
pub fn expiretime(&mut self, key: &str) -> Result<ScalarValue, StreamError>
Returns the absolute Unix timestamp in seconds at which the given key will expire.
§Arguments
key- The key to get the expiry time of.
§Returns
- [
Value] - The Unix timestamp in seconds.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn flushdb(&mut self) -> Result<ScalarValue, StreamError>
pub fn flushdb(&mut self) -> Result<ScalarValue, StreamError>
Deletes all keys present in the database.
Sourcepub fn get(&mut self, key: &str) -> Result<ScalarValue, StreamError>
pub fn get(&mut self, key: &str) -> Result<ScalarValue, StreamError>
Returns the value for the given key.
§Arguments
key- The key to get the value of.
§Returns
- [
Value] - The value of the key. Returns a valid [Value::VNull] variant if the key does not exist.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn getdel(&mut self, key: &str) -> Result<ScalarValue, StreamError>
pub fn getdel(&mut self, key: &str) -> Result<ScalarValue, StreamError>
Sourcepub fn getex(
&mut self,
key: &str,
option: GetexOption,
) -> Result<ScalarValue, StreamError>
pub fn getex( &mut self, key: &str, option: GetexOption, ) -> Result<ScalarValue, StreamError>
Returns the value for the given key and optionally sets its expiration.
§Arguments
key- The key to get the value of.option:GetexOption- The option to specify conditions for setting the expiry.
§Returns
- [
Value] - The value of the key. Returns a valid [Value::VNull] variant if the key does not exist.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn incr(&mut self, key: &str) -> Result<ScalarValue, StreamError>
pub fn incr(&mut self, key: &str) -> Result<ScalarValue, StreamError>
Increments the integer at key by one. Creates key as 1 if absent.
/// # Arguments
key- The key to increment.
§Returns
- [
Value] - The new value ofkey.
§Errors
StreamError- If an error occured in the communication stream, or if the key is not an integer.
Sourcepub fn incrby(
&mut self,
key: &str,
delta: i64,
) -> Result<ScalarValue, StreamError>
pub fn incrby( &mut self, key: &str, delta: i64, ) -> Result<ScalarValue, StreamError>
Sourcepub fn ping(&mut self) -> Result<ScalarValue, StreamError>
pub fn ping(&mut self) -> Result<ScalarValue, StreamError>
Returns PONG if no argument is provided, otherwise it returns PONG with the message argument.
§Returns
- [
Value] - The response from the server, with PONG if no argument is provided.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn set<T: Into<SetInput>>(
&mut self,
key: &str,
value: T,
) -> Result<ScalarValue, StreamError>
pub fn set<T: Into<SetInput>>( &mut self, key: &str, value: T, ) -> Result<ScalarValue, StreamError>
Sets the value of a key.
§Arguments
key- The key to set the value of.value- The value to set.
§Returns
- [
Value] - A response from the server with an OK if succes.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn setget<T: Into<SetInput>>(
&mut self,
key: &str,
value: T,
) -> Result<ScalarValue, StreamError>
pub fn setget<T: Into<SetInput>>( &mut self, key: &str, value: T, ) -> Result<ScalarValue, StreamError>
Sets the value of a key and returns the previous value.
§Arguments
key- The key to set the value of.value- The value to set.
§Returns
- [
Value] - The previous value of the key.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn hset<'a, T: Into<HSetInput<'a>>>(
&mut self,
key: &str,
fields: T,
) -> Result<ScalarValue, StreamError>
pub fn hset<'a, T: Into<HSetInput<'a>>>( &mut self, key: &str, fields: T, ) -> Result<ScalarValue, StreamError>
Sets the value of a field in a set for a key. Yields a OK result if operation went okay, and an integer value for number of fields updated.
§Arguments
key- The key to set the value of.fields- The fields to set.
§Returns
- [
Value] - A response from the server with an OK if succes and the number of updated fields.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn hget(
&mut self,
key: &str,
field: &str,
) -> Result<ScalarValue, StreamError>
pub fn hget( &mut self, key: &str, field: &str, ) -> Result<ScalarValue, StreamError>
Gets the value of a field in a set for a key.
§Arguments
key- The key to get the value of.field- The field to get the value of.
§Returns
- [
Value] - The value of the field, VNull if the field does not exist.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn hgetall(&mut self, key: &str) -> Result<HSetValue, StreamError>
pub fn hgetall(&mut self, key: &str) -> Result<HSetValue, StreamError>
Gets all fields for a set for a key.
§Arguments
key- The key to get the fields of.
§Returns
- [
Value] - A list of fields and their values. TODO: Probalby wrong
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn setex<T: Into<SetInput>>(
&mut self,
key: &str,
value: T,
option: SetOption,
) -> Result<ScalarValue, StreamError>
pub fn setex<T: Into<SetInput>>( &mut self, key: &str, value: T, option: SetOption, ) -> Result<ScalarValue, StreamError>
Sets the value of a key with an expiration time.
§Arguments
key- The key to set the value of.value- The value to set.option:SetOption- The option to specify conditions for setting the expiry.
§Returns
- [
Value] - A response from the server with an OK if succes.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn ttl(&mut self, key: &str) -> Result<ScalarValue, StreamError>
pub fn ttl(&mut self, key: &str) -> Result<ScalarValue, StreamError>
Returns the remaining time to live (in seconds) of a key that has an expiration set.
§Arguments
key- The key to get the time to live of.
§Returns
- [
Value] - The remaining time to live in seconds.
§Errors
StreamError- If an error occured in the communication stream.
Sourcepub fn dtype(&mut self, key: &str) -> Result<ScalarValue, StreamError>
pub fn dtype(&mut self, key: &str) -> Result<ScalarValue, StreamError>
Returns the type of the value stored at key as a string.
§Arguments
key- The key to get the type of.
§Returns
- [
Value] - The type of the value stored atkey, as a [Value::VStr] variant.
§Errors
StreamError- If an error occured in the communication stream.
Source§impl Client
impl Client
Sourcepub fn get_watch(
&mut self,
key: &str,
) -> Result<(WatchStream, ScalarValue), ClientError>
pub fn get_watch( &mut self, key: &str, ) -> Result<(WatchStream, ScalarValue), ClientError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl UnwindSafe for Client
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> 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> 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