Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to write the code of java client Jedis of Redis

Shulou Source: shulou.com Published: 2022-06-02 02:28:03 10月16日 Update

This article will explain in detail how to write the code of Java client Jedis of Redis. The content of the article is of high quality. Therefore, Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.

1. Steps

(1) Guide jar packages: Commons-pool-1.6.jar and Jedis-2.1.0.jar;

(2) Create Jedis objects to operate Redis database.

//Note: Eclipse in the host needs to set the following two points to connect to the virtual machine Redis// 1) Disable Linux firewall: systemctl stop firewalld.service;// 2) Comment out bind 127.0.0.1 in redis.conf and set protect-mode no.

2. Code example

public class Test { public static void main(String[] args) { //Create a Jedis object to connect Redis with IP and port number Jedis jedis = new Jedis("192.168.153.131",6379); //Java methods work the same as Linux commands String result = jedis.ping(); System.out.println(result); jedis.set("a", "wanglei"); String a = jedis.get("a"); System.out.println(a); //Close connection jedis.close(); } } About Redis Java client Jedis code how to write to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Code client client content object article more knowledge article good consistent host function parameter slogan command data database method step Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple MySQL Redmi Docker