Skip to main content

Client

Struct Client 

Source
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

Source

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

Source

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 of key.
§Errors
  • StreamError - If an error occured in the communication stream.
Source

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 of key.
§Errors
  • StreamError - If an error occured in the communication stream.
Source

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.
Source

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.
Source

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, only key is checked.
§Returns
  • [Value] - The number of keys that exist.
§Errors
  • StreamError - If an error occured in the communication stream.
Source

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.
Source

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.
Source

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.
Source

pub fn flushdb(&mut self) -> Result<ScalarValue, StreamError>

Deletes all keys present in the database.

Source

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.
Source

pub fn getdel(&mut self, key: &str) -> Result<ScalarValue, StreamError>

Returns the value for the given key and then deletes the key.

§Arguments
  • key - The key to get the value of and delete.
§Returns
  • [Value] - The value of the key. Returns a valid [Value::VNull] variant if the key does not exist.
Source

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.
Source

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 of key.
§Errors
  • StreamError - If an error occured in the communication stream, or if the key is not an integer.
Source

pub fn incrby( &mut self, key: &str, delta: i64, ) -> Result<ScalarValue, StreamError>

Increments the integer at key by delta. Creates key as delta if absent.

§Arguments
  • key - The key to increment.
  • delta - The amount to increment by.
§Returns
  • [Value] - The new value of key, or an error if the key is not an integer.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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 at key, as a [Value::VStr] variant.
§Errors
  • StreamError - If an error occured in the communication stream.
Source§

impl Client

Source

pub fn get_watch( &mut self, key: &str, ) -> Result<(WatchStream, ScalarValue), ClientError>

Get a watch stream for a key.

[!WARNING] This operation is non deterministic, but will at best effort yield changes.

§Arguments
  • key - The key to watch
§Returns
  • A watch stream and the first value of the key
§Errors
  • If the watch stream could not be created

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more