Redis CRUD Operations with Jedis

Jedis is a powerful Java client library for Redis that supports all CRUD (Create, Read, Update, Delete) operations. In this blog post, we will focus on the Delete operation.


Installation

You can download Jedis from https://mvnrepository.com/artifact/redis.clients/jedis.
Once downloaded, add the jedis-3.6.3.jar file to your project’s classpath.

jar.png


Local Installation

  • Copy the jedis-3.6.3.jar file to the /lib folder of your project.

windows.png

Remote Installation

  • Use Xshell and Xftp to upload the jedis-3.6.3.jar file to the /lib folder on your remote server.

BeanShell Script

In this example, we will demonstrate how to use Jedis to delete a key from Redis.
For more information about the methods provided by Jedis, please refer to https://github.com/redis/jedis.

import redis.clients.jedis.Jedis;
import org.apache.commons.lang3.StringUtils;

String host = "${redis-host}";
int port = ${redis-port};
String password = "${redis-password}";
int index = ${db};
String key = "${key}";


Jedis jedis = new Jedis(host, port);
if(StringUtils.isNotBlank(password)){
jedis.auth(password);
}
jedis.select(index);

if (jedis.exists(key)){
jedis.del(key);
}

Make sure to replace the variables ${redis-host}, ${redis-port}, ${redis-password}, ${db}, and ${key} with the appropriate values for your Redis instance.

All of it! With this script, you can easily delete a key from Redis using Jedis.