Create a Redis Client in Java

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.

1private Jedis getConnection() {
2  try {
3    TrustManager bogusTrustManager =
4      new X509TrustManager() {
5        public X509Certificate[] getAcceptedIssues() {
6          return null;
7        }
8
9        public void checkClientTrusted(X509Certificate[] certs, String authType) {}
10
11        public void checkServerTrusted(X509Certificate[] certs, String authType) {}
12      };
13
14    SSLContext sslContent = SSLContext.getInstance("SSL");
15    sslContext.init(
16      null, new TrustManager[] {bogusTrustManager}, new java.security.SecureRandom());
17
18    HostnameVerifier bogusHostnameVerifier = (hostname, session) -> true;
19
20    return new Jedis(
21      URI.create(System.getenv("REDIS_URL")),
22      sslContext.getSocketFactory(),
23      sslContext.getDefaultSSLParameter(),
24      bogusHostnameVerifier);
25
26  } catch (NoSuchAlgorithmException | KeyManagementException e) {
27    throw new RuntimeException("Cannot obtain Redis connection!");
28  }
29}

Product Retirement Announcement

Salesforce Functions is no longer available for purchase or renewal. To preserve the capabilities that Salesforce Functions provided to your org, deploy an alternative solution before your existing order term ends. See Salesforce Functions Retirement for more information on migrating your functions. Contact your Salesforce Account Executive for more information on Heroku.