Skip to main content

PaperClient

Struct PaperClient 

Source
pub struct PaperClient { /* private fields */ }

Implementations§

Source§

impl PaperClient

Source

pub fn new(paper_addr: impl FromPaperAddr) -> PaperClientResult<Self>

Creates a new instance of the client and connects to the server. If a connection could not be established, a PaperClientError is returned.

§Examples
use paper_client::PaperClient;

let client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
Source

pub fn ping(&mut self) -> PaperClientResult<PaperValue>

Pings the server.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.ping() {
    Ok(value) => println!("{value:?}"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn version(&mut self) -> PaperClientResult<PaperValue>

Gets the cache version.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.version() {
    Ok(value) => println!("{value:?}"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn auth(&mut self, token: impl AsPaperAuthToken) -> PaperClientResult<()>

Attempts to authorize the connection with the supplied auth token. This must match the auth token specified in the server’s configuration to be successful.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.auth("my_token") {
    Ok(_) => println!("done"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn get(&mut self, key: impl AsPaperKey) -> PaperClientResult<PaperValue>

Gets the value of the supplied key from the cache.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.get("key") {
    Ok(value) => println!("{value:?}"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn set( &mut self, key: impl AsPaperKey, value: impl TryInto<PaperValue>, ttl: Option<u32>, ) -> PaperClientResult<()>

Sets the supplied key, value, and ttl to the cache.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.set("key", "value", None) {
    Ok(_) => println!("done"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn del(&mut self, key: impl AsPaperKey) -> PaperClientResult<()>

Deletes the value of the supplied key from the cache.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.del("key") {
    Ok(_) => println!("done"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn has(&mut self, key: impl AsPaperKey) -> PaperClientResult<bool>

Checks if the cache contains an object with the supplied key without altering the eviction order of the objects.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.has("key") {
    Ok(has) => println!("{has}"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn peek(&mut self, key: impl AsPaperKey) -> PaperClientResult<PaperValue>

Gets (peeks) the value of the supplied key from the cache without altering the eviction order of the objects.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.peek("key") {
    Ok(value) => println!("{value:?}"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn ttl( &mut self, key: impl AsPaperKey, ttl: Option<u32>, ) -> PaperClientResult<()>

Sets the TTL associated with the supplied key.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.ttl("key", Some(5)) {
    Ok(_) => println!("done"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn size(&mut self, key: impl AsPaperKey) -> PaperClientResult<u32>

Gets the size of the value of the supplied key from the cache in bytes.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.size("key") {
    Ok(size) => println!("{size}"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn wipe(&mut self) -> PaperClientResult<()>

Wipes the contents of the cache.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.wipe() {
    Ok(_) => println!("done"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn resize(&mut self, size: u64) -> PaperClientResult<()>

Resizes the cache to the supplied size.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.resize(10) {
    Ok(_) => println!("done"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn policy(&mut self, policy: PaperPolicy) -> PaperClientResult<()>

Sets the cache’s eviction policy.

§Examples
use paper_client::{PaperClient, PaperPolicy};

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.policy(PaperPolicy::Lru) {
    Ok(_) => println!("done"),
    Err(err) => println!("{err:?}"),
}
Source

pub fn status(&mut self) -> PaperClientResult<Status>

Gets the cache’s status.

§Examples
use paper_client::PaperClient;

let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();

match client.status() {
    Ok(status) => println!("{status:?}"),
    Err(err) => println!("{err:?}"),
}

Trait Implementations§

Source§

impl Debug for PaperClient

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.