wget https://repo1.maven.org/maven2/redis/clients/jedis/4.3.1/jedis-4.3.1.jarwget https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jarwget https://repol.maven.org/maven2/org/apache/commons/commons-pool2/2.11.1/commons-pool2-2.11.1.jar

import redis.clients.jedis.Jedis;public class HelloRedis {public static void main(String[] args) {try {/**The following parameters: if you are accessing via the private network, fill in the private IP address, port number, instance ID, and password of your distributed cache database instance;Configure the instance's public network address, port number, and password in case of public network access.*/String host = "192.xx.xx.195";int port = 6379;String instanceid = "crs-09xxxqv";String password = "123ad6aq";// Connect to RedisJedis jedis = new Jedis(host, port);// Authenticatejedis.auth(instanceid + ":" + password);/**For operating instances, refer to https://github.com/xetorthio/jedis */// Set the keyjedis.set("redis", "tencent");System.out.println("set key redis suc, value is: tencent");// Get the keyString value = jedis.get("redis");System.out.println("get key redis is: " + value);// Close and exitjedis.quit();jedis.close();} catch (Exception e) {e.printStackTrace();}}}

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;import redis.clients.jedis.Jedis;import redis.clients.jedis.JedisPool;import javax.net.ssl.SSLContext;import javax.net.ssl.SSLSocketFactory;import javax.net.ssl.TrustManager;import javax.net.ssl.TrustManagerFactory;import java.io.FileInputStream;import java.io.InputStream;import java.security.KeyStore;import java.security.SecureRandom;public class Main {public static void main(String[] args) throws Exception {KeyStore trustStore = KeyStore.getInstance("jks");// `ca.jks` is the certificate file name.try (InputStream inputStream = new FileInputStream("ca.jks") ){trustStore.load(inputStream, null);}TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("PKIX");trustManagerFactory.init(trustStore);TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();SSLContext sslContext = SSLContext.getInstance("TLS");sslContext.init(null, trustManagers, new SecureRandom());SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();//with ssl config jedis pool// `vip` is the private IPv4 address for database connection, `6379` is the default port number, and `pwd` is the password of the default account. You need to replace them as needed.JedisPool pool = new JedisPool(genericObjectPoolConfig, "vip",6379, 2000, "pwd", 0, true, sslSocketFactory, null, null);Jedis jedis = pool.getResource();System.out.println(jedis.ping());jedis.close();}}
javac -cp ".:lib/*" src/HelloRedis. java -d ./java-cp ".:lib/*" HelloRedis
Feedback