In order to use Redis in Java applications, we need a Redis Java client. There are a couple of choices that can be found under the Clients
section on the Redis homepage. In this recipe, we will introduce Jedis, which is an open source and easy to use Redis Java client.
You need to finish the installation of the Redis Server as we described in the Downloading and installing Redis recipe in Chapter 1, Getting Started with Redis.
You need to install the Java Development Kit (JDK), version 1.8.
A Java IDE such as IntelliJ IDEA or NetBeans is recommended but not required.
To show how to connect Redis with Java, the first requirement for using Jedis in our Java application is including the library in the project. We can either download the Jedis library JAR file and add its path to CLASSPATH
, or use build tools such as Maven, Gradle, or Bazel to manage the library dependencies. In examples of this recipe, we use Gradle to include Jedis as...