|
22 | 22 | import com.genexus.util.GXService;
|
23 | 23 | import com.genexus.util.GXServices;
|
24 | 24 |
|
25 |
| -import redis.clients.jedis.Jedis; |
26 |
| -import redis.clients.jedis.JedisPool; |
27 |
| -import redis.clients.jedis.JedisPoolConfig; |
28 |
| -import redis.clients.jedis.Pipeline; |
| 25 | +import redis.clients.jedis.*; |
29 | 26 |
|
30 | 27 |
|
31 | 28 | public class RedisClient implements ICacheService2, Closeable {
|
32 | 29 | public static final ILogger logger = LogManager.getLogger(RedisClient.class);
|
33 | 30 | private String keyPattern = "%s_%s_%s"; //Namespace_KEY
|
34 | 31 | private static int REDIS_DEFAULT_PORT = 6379;
|
| 32 | + private static String REDIS_SCHEMA = "redis://"; |
| 33 | + private static String REDIS_SSL_SCHEMA = "rediss://"; |
35 | 34 | private JedisPool pool;
|
36 | 35 | private ObjectMapper objMapper;
|
37 | 36 |
|
@@ -60,24 +59,31 @@ private void initCache(String hostOrRedisURL, String password, String cacheKeyPa
|
60 | 59 | String host = "127.0.0.1";
|
61 | 60 | hostOrRedisURL = isNullOrEmpty(hostOrRedisURL) ? host: hostOrRedisURL;
|
62 | 61 | int port = REDIS_DEFAULT_PORT;
|
| 62 | + int database = Protocol.DEFAULT_DATABASE; |
| 63 | + boolean ssl; |
63 | 64 |
|
64 |
| - boolean isRedisURIScheme = hostOrRedisURL.startsWith("redis://"); |
65 |
| - String sRedisURI = isRedisURIScheme ? hostOrRedisURL : "redis://" + hostOrRedisURL; |
| 65 | + boolean isRedisURIScheme = hostOrRedisURL.startsWith(REDIS_SCHEMA) || hostOrRedisURL.startsWith(REDIS_SSL_SCHEMA); |
| 66 | + String sRedisURI = isRedisURIScheme ? hostOrRedisURL : REDIS_SCHEMA + hostOrRedisURL; |
66 | 67 |
|
67 | 68 | try {
|
68 | 69 | URI redisURI = new URI(sRedisURI);
|
69 | 70 | host = redisURI.getHost();
|
70 | 71 | if (redisURI.getPort() > 0) {
|
71 | 72 | port = redisURI.getPort();
|
72 | 73 | }
|
| 74 | + String path = redisURI.getPath(); |
| 75 | + if (path != null && path.length() > 1) { |
| 76 | + database = Integer.parseInt(path.substring(1)); |
| 77 | + } |
| 78 | + ssl = redisURI.getScheme().equals("rediss"); |
73 | 79 | } catch (URISyntaxException e) {
|
74 | 80 | logger.error(String.format("Could not parse Redis URL. Check for supported URLs: %s" , sRedisURI), e);
|
75 | 81 | throw e;
|
76 | 82 | }
|
77 | 83 |
|
78 | 84 | password = (!isNullOrEmpty(password)) ? Encryption.tryDecrypt64(password) : null;
|
79 | 85 |
|
80 |
| - pool = new JedisPool(new JedisPoolConfig(), host, port, redis.clients.jedis.Protocol.DEFAULT_TIMEOUT, password); |
| 86 | + pool = new JedisPool(new JedisPoolConfig(), host, port, redis.clients.jedis.Protocol.DEFAULT_TIMEOUT, password, database, ssl); |
81 | 87 |
|
82 | 88 | objMapper = new ObjectMapper();
|
83 | 89 | objMapper
|
|
0 commit comments