sorccu / r2d2-redis

MIT License
101 stars 42 forks source link

when I use r2d2-redis, I got error cannot resolve `_: redis::FromRedisValue` #24

Closed arlicle closed 5 years ago

arlicle commented 5 years ago
    let manager = RedisConnectionManager::new("redis://127.0.0.1:6379").unwrap();
    let pool = r2d2::Pool::builder().build(manager).unwrap();
    let pool2 = pool.clone();
    let mut conn = pool.get().unwrap();
    let n: i64 = conn.incr("counter", 1).unwrap();
    let con = *conn;
    let x = conn.set("ccc", 10);

get error

error[E0283]: type annotations required: cannot resolve `_: redis::FromRedisValue`
  --> src/db/redis.rs:17:18
   |
17 |     let x = conn.set("ccc", 10);
   |     

or I use

redis::cmd("SET").arg("my_key").arg(42).execute(&mut *conn); this code is ok

but when I use

redis::cmd("GET").arg("my_key").query(&mut *conn); get the same error

error[E0283]: type annotations required: cannot resolve `_: redis::FromRedisValue`
  --> src/db/redis.rs:18:37
   |
18 |     redis::cmd("GET").arg("my_key").query(&mut *conn);

How can I fix it ?

arlicle commented 5 years ago

I Fixed it ,

    let x: () = conn.set("abc", 1000).unwrap();
    let y: i32 = conn.get("abc").unwrap();