Giter VIP home page Giter VIP logo

redis-derive's Introduction

skills

kkharji's stats kkharji's languages

redis-derive's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

redis-derive's Issues

Add support for tuple structs

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.

Doesn't seem to work well with `BLPOP` and `PUSH`?

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.

Support fixed-sized arrays

Thank you for making this!

Opening this issue to track discussion about supporting fixed-sized arrays.

Non-existent keys throw an odd error instead of `Option::None`

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

#(#idents: redis::from_redis_value(
expects fields to exist and simply defaults to Nil otherwise, which cannot be converted into String

No Support for Enum's

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.