matrix-sdk-redis

Crates.iomatrix-sdk-redis
lib.rsmatrix-sdk-redis
version0.1.1
sourcesrc
created_at2024-11-21 16:22:01.028288
updated_at2024-11-21 16:38:59.533665
descriptionRedis Storage backend for matrix-sdk
homepagehttps://codeberg.org/andybalaam/matrix-sdk-redis
repositoryhttps://codeberg.org/andybalaam/matrix-sdk-redis
max_upload_size
id1456357
size86,697
Andy Balaam (andybalaam)

documentation

README

Redis store for matrix-rust-sdk

This allows us to use a Redis database to hold a crypto store for matrix-rust-sdk.

Status: experimental

This works for me, but is not proven and probably has some bugs where actions that should be atomic are not.

It's even possible that Redis is just not a suitable DB to use as a Matrix crypto store.

Some features are missing - see "Limitations" below.

How to use

Here is a minimal example of how to create a matrix-rust-sdk Client that uses a Redis store to hold its crypto information.

First, depend on the latest versions of matrix-sdk and matrix-sdk-redis in Cargo.toml:

..
[dependencies]
...
matrix-sdk = { version = "...", default-features = false, features = [ "e2e-encryption", "rustls-tls" ] }
matrix-sdk-redis = "..."
...

Second, call make_store_config in matrix_sdk_redis and pass the result in to store_config on your ClientBuilder instance,.

The arguments to make_store_config are a URL for your Redis server, an optional passphrase encrypt your store, and a prefix that will be prepended to every key in Redis.

use matrix_sdk::{config::SyncSettings, Client};
use matrix_sdk_redis;

#[tokio::main]
async fn main() {
    let client = Client::builder()
        .homeserver_url("http://localhost:8008")
        .store_config(
            matrix_sdk_redis::make_store_config(
                "redis://127.0.0.1/", None, "my_prefix"
            ).await?
        ).await
        .unwrap()
        .build()
        .await
        .unwrap();

    client.login_username("myuser", "mypassword").await.unwrap();

    let response = client.sync_once(SyncSettings::default()).await.unwrap();
    println!("{:?}", response);
}

Limitations

  • Currently, there is no state store, only a crypto store. The crypto store allows us to retain our identity between executions of the program. Without a state store, we must re-sync a lot of information from the server every time we start, which is less efficient.

  • TODO: Redis keys are not currently obfuscated with the store cipher (values are).

  • TODO: Does not provide cross-process locking. Calling try_take_leased_lock always panics.

  • TODO: does not make use of backup_version to make resetting backups faster. (At time of writing the SQLite version has the same limitation, so it's not too bad.)

  • insert_custom_value_if_missing can potentially return true even though it actually did not insert a value because one already existed. This should be rare.

Testing against a real Redis

If you have a local Redis installed on 127.0.0.1 you can simply run:

cargo test --features=real-redis-tests

Copyright

This is written by Andy Balaam, but some of it was on (authorised) company time working for Element. The code is donated to the The Matrix.org Foundation C.I.C.

Copyright 2022-2024 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0. More detail in LICENSE.

Commit count: 0

cargo fmt