Error accessing another Redis database using redis container: Invalid database number

I am trying to access Redis using a box redis

(version 0.3.1). It throws an invalid database .

extern crate redis;

use redis::*;
use std::string::String;
use std::collections::HashSet;

fn main() {
   if let Err(e) = read_meta_keys_redis("myset".to_string()) {
     println!("{}", e.description());
   }
 }

fn read_meta_keys_redis(key: String) -> redis::RedisResult<()> {
  println!("22{}", key);
  let client = try!(redis::Client::open("redis://127.0.0.1:6379/2"));

  let con = try!(client.get_connection());
  let mems: HashSet<i32> = try!(con.smembers(key));
  for x in mems.iter() {
      println!("op-->{}", x);
  }
  Ok(())
}

      

my local redis

: Run the following commands in a shell   redis-cli select 2 sadd myset "hello" sadd myset "how are you"

127.0.0.1:6379[2]> smembers myset 
  1) "hello" 2) "how are you" 
127.0.0.1:6379[2]>

      

There may be some background in my previous question <Quiet error while accessing Redis .

+3


source to share


1 answer


Error from inside the box :

path => path.parse::<i64>().unwrap_or(
    fail!((ErrorKind::InvalidClientConfig, "Invalid database number"))),

      



Unfortunately, this is just a programming error. unwrap_or

always evaluates the argument, which in this case is a macro fail!

. It looks like it should be unwrap_or_else

that accepts a closure that only executes on failure.

I submitted a PR to fix an immediate issue. As a workaround, you can create a structure directly redis::ConnectionInfo

and point the database there.

+2


source







All Articles