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");
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();
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();
}
}
Was this page helpful?