pub struct RedisBackend { /* private fields */ }
Expand description

An implementation of ExpiryStore based on redis using redis-rs async runtime

Example

use actix_storage::Storage;
use actix_storage_redis::{RedisBackend, ConnectionInfo,RedisConnectionInfo, ConnectionAddr};
use actix_web::{App, HttpServer};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    const THREADS_NUMBER: usize = 4;
    let store = RedisBackend::connect_default();
    // OR
    let connection_info = ConnectionInfo {
        addr: ConnectionAddr::Tcp("127.0.0.1".to_string(), 1234).into(),
        redis: RedisConnectionInfo{
            db: 0,
            username: Some("god".to_string()),
            password: Some("bless".to_string()),
        }
    };
    let store = RedisBackend::connect(connection_info).await.expect("Redis connection failed");

    let storage = Storage::build().expiry_store(store).finish();
    let server = HttpServer::new(move || {
        App::new()
            .data(storage.clone())
    });
    server.bind("localhost:5000")?.run().await
}

requires [“actor”] feature

Implementations§

Connect using the provided connection info

Connect using the default redis port on local machine

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Remove all expiry requests from a key and make it persistent, the persistenty can be overwriten by calling expire on the key.
Gets expiry for a key, returning None means it doesn’t have an expiry, if the provider can’t return an expiry, it should return an error instead. The result of this function can have some error, but it should be documented.
Sets an expiry for a key, the key may or may not be removed based on implementation, but it should be guaranteed that it won’t appear in get based methods or contains checks after the period specified.
Extend expiry for a key for another duration of time. If the key doesn’t have an expiry, it should be equivalent of calling expire.
A notification that should be implemented if expiry is a different entity that store itself to remove expiry when set is called for a key.
Set a key-value for a duration of time, if the key already exists, it should overwrite both the value and the expiry for that key.
Get the value and expiry for a key, it is possible to return None if the key doesn’t exist, or return None for the expiry if the key is persistent.
Set a key-value pair, if the key already exist, value should be overwritten
Get a value for specified key, it should result in None if the value does not exist
Delete the key from storage, if the key doesn’t exist, it shouldn’t return an error
Check if key exist in storage

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more