Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking Change #1047

Open
zebede22 opened this issue Feb 4, 2024 · 11 comments
Open

Breaking Change #1047

zebede22 opened this issue Feb 4, 2024 · 11 comments

Comments

@zebede22
Copy link

zebede22 commented Feb 4, 2024

I recently upgraded my redis crate from version 0.23 to 0.24. Previously, the following code snippet was working fine:

static CLIENT: Lazy<Client> =
    Lazy::new(|| Client::open("redis://xxx:1234").expect("Failed to connect to redis"));

pub async fn get_json(key: &str) -> RedisResult<Value> {
    let mut conn = CLIENT.get_tokio_connection().await?;
    let Json(json_data) = conn.json_get(key, "$").await?;

    Ok(json_data)
}

However, after upgrading to version 0.24, I started receiving an error message without making any changes to the code. Can anyone explain what might have caused this issue?

error[E0277]: the trait bound `redis_macros::Json<_>: FromRedisValue` is not satisfied
   --> src/redis.rs:14:32
    |
14  |     let Json(json_data) = conn.json_get(key, "$").await?;
    |                                ^^^^^^^^ the trait `FromRedisValue` is not implemented for `redis_macros::Json<_>`
    |
    = help: the following other types implement trait `FromRedisValue`:
              bool
              isize
              i8
              i16
              i32
              i64
              i128
              usize
            and 44 others
note: required by a bound in `redis::JsonAsyncCommands::json_get`
   --> /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redis-0.24.0/src/commands/json.rs:177:1
    |
177 | / implement_json_commands! {
178 | |     'a
179 | |     
180 | |     /// Append the JSON `value` to the array at `path` after the last element in it.
...   |
298 | |     fn json_get<K: ToRedisArgs, P: ToRedisArgs>(key: K, path: P) {
    | |        -------- required by a bound in this associated function
...   |
388 | |     }
389 | | }
    | |_^ required by this bound in `JsonAsyncCommands::json_get`
    = note: this error originates in the macro `implement_json_commands` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
@zebede22
Copy link
Author

zebede22 commented Feb 4, 2024

^^^^^^^^ the trait `FromRedisValue` is not implemented for `serde_json::Value`

If I specify type it works let json_data: String, but I don't know the structure, it's a json data, so it's serde_json::Value

@nihohit
Copy link
Contributor

nihohit commented Feb 6, 2024

@zebede22 are you sure this isn't an issue with the redis-macros crate? can you provide an example that relies only on redis-rs?

@zebede22
Copy link
Author

zebede22 commented Feb 6, 2024

@zebede22 are you sure this isn't an issue with the redis-macros crate? can you provide an example that relies only on redis-rs?

Yes, redis-rs is not related.
Here same code without the redis-crate:

 let json_data: Value = conn.json_get(key, "$").await?;

Error:

error[E0277]: the trait bound `serde_json::Value: FromRedisValue` is not satisfied
   --> src/redis.rs:14:33
    |
14  |     let json_data: Value = conn.json_get(key, "$").await?;
    |                                 ^^^^^^^^ the trait `FromRedisValue` is not implemented for `serde_json::Value`
    |
    = help: the following other types implement trait `FromRedisValue`:
              bool
              isize
              i8
              i16
              i32
              i64
              i128
              usize
            and 44 others
note: required by a bound in `redis::JsonAsyncCommands::json_get`

@nihohit
Copy link
Contributor

nihohit commented Feb 6, 2024

is serde_json::Value supposed to implement FromRedisValue? if so, where is it implemented?
Again, that's not a redis-rs type, so it's hard for me to understand whether this is an issue in redis-rs or not.

@zebede22
Copy link
Author

zebede22 commented Feb 7, 2024

is serde_json::Value supposed to implement FromRedisValue? if so, where is it implemented? Again, that's not a redis-rs type, so it's hard for me to understand whether this is an issue in redis-rs or not.

It's been working until 0.24 change.

Also, how to get a json from an endpoint where you have no exact json structure? how it can be done without serde_json?

@nihohit
Copy link
Contributor

nihohit commented Feb 7, 2024

how to get a json from an endpoint where you have no exact json structure? how it can be done without serde_json?

You can use a HashMap, or a string. We're trying to understand what changed, and the more moving parts there are, the harder it is to pinpoint the source of the issue.

It's been working until 0.24 change.

Maybe, but I need a minimal reproducible example in order to understand the issue. If you want to create a small project to simulate the problem, that will be very helpful.

@Dav1dde
Copy link
Contributor

Dav1dde commented Mar 26, 2024

Sounds like you have two separate versions of redis in your dependency tree. Looking at the redis-macros crate it does infact have redis version 0.23 as a dependency which is not semver compatible with 0.24.

-> Not related to the redis crate, you just need to use the same version or ask redis-marcros to update the dependency.

@samgj18
Copy link

samgj18 commented May 5, 2024

This is still happening, just happened to me after upgrading. I believe this is a redis-rs issue rather than another lib issue.

@Dav1dde
Copy link
Contributor

Dav1dde commented May 5, 2024

Check your Cargo.lock or cargo tree, it is very likely you have two separate versions of the redis crate in your dependencies.

@samgj18
Copy link

samgj18 commented May 5, 2024

image I went over both before trying to find a solution here. What I thought could be the culprit, deadpool-redis, also has the same dep [see here](https://github.com/bikeshedder/deadpool/blob/master/redis/Cargo.toml#L40).

@nihohit
Copy link
Contributor

nihohit commented Jun 27, 2024

@zebede22 does this still happen? can you provide a reproducing example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants