For Salesforce Functions written in Java, access your Redis datastore with the Jedis Redis client. Access environment variable REDIS_URL using method System.getenv to create a Redis client instance.
private Jedis getConnection() {
try {
TrustManager bogusTrustManager =
new X509TrustManager() {
public X509Certificate[] getAcceptedIssues() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
};
SSLContext sslContent = SSLContext.getInstance("SSL");
sslContext.init(
null, new TrustManager[] {bogusTrustManager}, new java.security.SecureRandom());
HostnameVerifier bogusHostnameVerifier = (hostname, session) -> true;
return new Jedis(
URI.create(System.getenv("REDIS_URL")),
sslContext.getSocketFactory(),
sslContext.getDefaultSSLParameter(),
bogusHostnameVerifier);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new RuntimeException("Cannot obtain Redis connection!");
}
}