clia-redis-macros

Crates.ioclia-redis-macros
lib.rsclia-redis-macros
version
sourcesrc
created_at2024-11-29 02:58:49.84003
updated_at2024-11-29 02:58:49.84003
descriptionA derive to store and retrieve JSON values in redis encoded using serde.
homepage
repositoryhttps://github.com/clia/redis-macros/
max_upload_size
id1465177
Cargo.toml error:TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
clia (clia)

documentation

README

clia-redis-macros

License Cargo Documentation

A derive to store and retrieve JSON values in redis encoded using serde.

Forked from https://github.com/Bajix/derive-redis-json

Example

Cargo.toml:

[dependencies]
clia-redis-macros = "0.2.0"

main.rs:

use std::sync::Arc;

use anyhow::Result;
use deadpool_redis::{redis::cmd, Pool as RedisPool};
use clia_redis_macros::RedisJsonValue;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, RedisJsonValue)]
pub struct User {
  pub id: u64,
  pub name: String,
}

pub async fn add_user(
  redis_pool: Arc<RedisPool>,
  user: User,
) -> Result<usize> {
  let mut conn = redis_pool.get().await?;
  let res: usize = cmd("SADD")
    .arg("Users")
    .arg(&user)
    .query_async(&mut conn)
    .await?;

  Ok(res)
}

pub async fn get_users(
  redis_pool: Arc<RedisPool>,
) -> Result<Vec<User>> {
  let mut conn = redis_pool.get().await?;
  let res: Vec<User> = cmd("SMEMBERS").arg("Users").query_async(&mut conn).await?;

  Ok(res)
}
Commit count: 2

cargo fmt