kkharji / redis-derive Goto Github PK
View Code? Open in Web Editor NEWThis crate implements the FromRedisValue and ToRedisArgs Traits from mitsuhiko / redis-rs for any struct
Home Page: https://docs.rs/redis-derive/
License: MIT License
This crate implements the FromRedisValue and ToRedisArgs Traits from mitsuhiko / redis-rs for any struct
Home Page: https://docs.rs/redis-derive/
License: MIT License
Just a heads up: HMSET (https://redis.io/commands/hmset/) has been depreciated in favor of HSET (https://redis.io/commands/hset/) as of Redis 4.0.0. At some point the docs should be updated, but it's not a big deal. The same command syntax should work.
Hey, thanks for writing this crate! It was super helpful. At some point, though, it would nice to have support for tuple structs. Just something to keep in mine.
I am trying to use this crate with PUSH
and BLPOP
and that doesn't seem to work. Particularly, when using BLPOP
, instead of having the entire struct returned, the deserialization fails. When introspecting the return value by just using redis::Value
, it appears that BLPOP
returns the name of the first field within the struct that I actually serialized.
Thank you for making this!
Opening this issue to track discussion about supporting fixed-sized arrays.
use redis_derive::{FromRedisValue, ToRedisArgs};
use std::collections::HashMap;
use redis::Commands;
#[derive(FromRedisValue, ToRedisArgs, Debug)]
enum Color {
Red,
Green,
}
#[derive(Default, FromRedisValue, ToRedisArgs, Debug)]
#[redis(rename_all = "snake_case")]
enum Group {
#[default]
MemberGroup,
AdminGroup,
}
#[derive(FromRedisValue, ToRedisArgs, Debug)]
struct MySuperCoolStruct {
first_field: String,
second_field: Option<i64>,
third_field: Vec<String>,
color: Color,
group: Group,
}
fn main() -> redis::RedisResult<()> {
let client = redis::Client::open("redis://127.0.0.1:6379/")?;
let mut con = client.get_connection()?;
let test1 = MySuperCoolStruct {
first_field: "Hello World".to_owned(),
second_field: Some(42),
third_field: vec!["abc".to_owned(), "cba".to_owned()],
color: Color::Red,
group: Group::AdminGroup,
};
// let _ = redis::cmd("HSET")
// .arg("test1")
// .arg(&test1)
// .query(&mut con)?;
let db_test1: MySuperCoolStruct = con.hgetall("test1")?;
println!("send : {:#?}, got : {:#?}", test1, db_test1);
let db_test1: HashMap<String, String> = con.hgetall("test1")?;
assert_eq!(db_test1["group"], "admin_group");
Ok(())
}
Error: Response was of incompatible type: "Response type not string compatible." (response was nil)
This happens because
redis-derive/src/data_struct.rs
Line 134 in 014526f
Nil
otherwise, which cannot be converted into String
Enum's do not work at this point in time due to that currently you can't implement a trait for the enum type in rust. I will sit down one weekend and probably figure out some workaround.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.