Create a new binary crate and add all of the necessary dependencies to the Cargo.toml file of that crate:
[dependencies]
clap = "2.32"
failure = "0.1"
r2d2 = "0.8"
r2d2_redis = "0.8"
redis = "0.9"
We added the dependencies that we used in the previous examples of this chapter—clap, failure, and r2d2. Also, we need the redis and r2d2_redis crates, which contain a connection manager for Redis so that we can use it with Pool from the r2d2 crate.
Next, let's import the types we need to create a tool:
use clap::{
crate_authors, crate_description, crate_name, crate_version,
App, AppSettings, Arg, SubCommand,
};
use redis::{Commands, Connection, RedisError};
use r2d2_redis::RedisConnectionManager;
use std::collections::HashMap;
Note the usage of some types. We imported Connection as a main connection type, which we will use to connect to a Redis instance. We also imported RedisConnectionManager from the r2d2_redis crate. This type allows Pool to create new connections. The last thing you should note is the Command trait. This trait contains methods that reflect the Redis client API. The names of methods are the same (but in lowercase), as you can see in the Redis protocol. We tested it manually in a previous section. The Command trait, implemented by a Connection struct, allows you to call methods of the Redis API.