Skip to content

Commit dbeb9c1

Browse files
authored
Merge pull request #297 from eclipse/added-redis-sentinel-and-cluster-support
[JNoSQL Redis Database API] - Fixed broken connection issue and added sentinel and cluster support
2 parents f11bdb4 + 2551582 commit dbeb9c1

17 files changed

+916
-122
lines changed

CHANGELOG.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
88

99
== [Unreleased]
1010

11+
=== Added
12+
- Added Redis Sentinel and Redis Cluster configuration at JNoSQL Redis Database API
13+
14+
=== Fixed
15+
- Fixed the broken connection issue at JNoSQL Redis Database API
16+
1117
== [1.1.2] - 2023-09-15
1218

1319
=== Added

README.adoc

Lines changed: 136 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,52 +1470,158 @@ You can use either the Maven or Gradle dependencies:
14701470

14711471
=== Configuration
14721472

1473-
This API provides the ```RedisConfigurations``` class to programmatically establish the credentials.
1473+
This is an example using Redis's Key-Value API with MicroProfile Config.
14741474
Please note that you can establish properties using the https://microprofile.io/microprofile-config/[MicroProfile Config] specification.
14751475

1476-
[cols="Redis"]
1477-
|===
1478-
|Configuration property |Description
1476+
[source,properties]
1477+
----
1478+
jnosql.keyvalue.provider=org.eclipse.jnosql.databases.redis.communication.RedisConfiguration
1479+
jnosql.keyvalue.database=heroes
1480+
----
14791481

1480-
|`jnosql.redis.host`
1481-
|The database host
1482+
This API provides enum classes to programmatically establish the credentials as:
14821483

1483-
|`jnosql.redis.port`
1484-
|The database port
1484+
- link:README.adoc#_single_node_configuration[`RedisConfigurations`] for single node configuration
1485+
+
1486+
[source,properties]
1487+
----
1488+
# Single Node Configuration
14851489
1486-
|`jnosql.redis.timeout`
1487-
|The redis timeout, the default value 2000 on milliseconds
1490+
# by default the host is localhost
1491+
jnosql.redis.host=localhost
1492+
# by default the port is 6379
1493+
jnosql.redis.port=6379
1494+
# if you have user
1495+
jnosql.redis.user=youruser
1496+
# if you have password
1497+
jnosql.redis.password=yourpassword
1498+
----
14881499

1489-
|`jnosql.redis.password`
1490-
|The user's password
1500+
- link:README.adoc#_redis_sentinel_configuration[`RedisSentinelConfigurations`] for sentinel configuration
1501+
+
1502+
[source,properties]
1503+
----
1504+
# Sentinel Configuration
1505+
jnosql.redis.sentinel.hosts=host1:26379,host2:26379
1506+
1507+
jnosql.redis.sentinel.master.name=masterName
1508+
jnosql.redis.sentinel.master.user=masterUser
1509+
jnosql.redis.sentinel.master.password=masterPassword
1510+
#jnosql.redis.sentinel.master.ssl=false
1511+
#jnosql.redis.sentinel.master.timeout=2000
1512+
#jnosql.redis.sentinel.master.connection.timeout=2000
1513+
#jnosql.redis.sentinel.master.socket.timeout=2000
1514+
1515+
jnosql.redis.sentinel.slave.user=slaveUser
1516+
jnosql.redis.sentinel.slave.password=slavePassword
1517+
#jnosql.redis.sentinel.slave.ssl=false
1518+
#jnosql.redis.sentinel.slave.timeout=2000
1519+
#jnosql.redis.sentinel.slave.connection.timeout=2000
1520+
#jnosql.redis.sentinel.slave.socket.timeout=2000
1521+
----
1522+
1523+
- link:README.adoc#_redis_sentinel_configuration[`RedisClusterConfigurations`] for cluster configuration
1524+
+
1525+
[source,properties]
1526+
----
1527+
# Cluster Configuration
14911528
1492-
|`jnosql.redis.database`
1493-
|The redis database number, the default value is 0
1529+
jnosql.redis.cluster.hosts=host1:6379,host2:6379
1530+
jnosql.redis.cluster.user=clusterUser
1531+
jnosql.redis.cluster.password=clusterPassword
1532+
jnosql.redis.cluster.client.name=clusterClientName
1533+
jnosql.redis.cluster.max.attempts=5
1534+
jnosql.redis.cluster.max.total.retries.duration=10000
1535+
#jnosql.redis.cluster.ssl=false
1536+
#jnosql.redis.cluster.timeout=2000
1537+
#jnosql.redis.cluster.connection.timeout=2000
1538+
#jnosql.redis.cluster.socket.timeout=2000
1539+
----
14941540

1495-
|`jnosql.redis.client.name`
1496-
|The client's name
1541+
==== Single Node Configuration
1542+
1543+
This API provides the `RedisConfigurations` class to programmatically establish the credentials.
1544+
Please note that you can establish properties using the https://microprofile.io/microprofile-config/[MicroProfile Config] specification.
14971545

1498-
|`jnosql.redis.max.total`
1499-
|The value for the maxTotal configuration attribute for pools created with this configuration instance, the default value 1000.
1546+
[cols="2,2", options="header"]
1547+
|===
1548+
|Configuration property |Description
15001549

1501-
|`jnosql.redis.max.idle`
1502-
|The value for the maxIdle configuration attribute for pools created with this configuration instance, the default value 10.
1550+
|`jnosql.redis.host` |The database host
1551+
|`jnosql.redis.port` |The database port
1552+
|`jnosql.redis.timeout` |The redis timeout, the default value is 2000 milliseconds
1553+
|`jnosql.redis.password` |The password's credential
1554+
|`jnosql.redis.database` |The redis database number
1555+
|`jnosql.redis.client.name` |The cluster client's name. The default value is 0.
1556+
|`jnosql.redis.max.total` |The value for the maxTotal configuration attribute for pools created with this configuration instance. The default value is 1000.
1557+
|`jnosql.redis.max.idle` |The value for the maxIdle configuration attribute for pools created with this configuration instance. The default value is 10.
1558+
|`jnosql.redis.min.idle` |The value for the minIdle configuration attribute for pools created with this configuration instance. The default value is 1.
1559+
|`jnosql.redis.max.wait.millis` |The value for the maxWait configuration attribute for pools created with this configuration instance. The default value is 3000 milliseconds.
1560+
|`jnosql.redis.connection.timeout` |The connection timeout in milliseconds configuration attribute for the jedis client configuration created with this configuration instance.
1561+
|`jnosql.redis.socket.timeout` |The socket timeout in milliseconds configuration attribute for the jedis client configuration with this configuration instance.
1562+
|`jnosql.redis.user` |The user configuration attribute for the jedis client configuration with this configuration instance.
1563+
|`jnosql.redis.ssl` |The ssl configuration attribute for the jedis client configuration with this configuration instance. The default value is false.
1564+
|`jnosql.redis.protocol` |The protocol configuration attribute for the jedis client configuration with this configuration instance.
1565+
|`jnosql.redis.clientset.info.config.disabled` |The clientset info disabled configuration attribute for the jedis client configuration with this configuration instance. The default value is false.
1566+
|`jnosql.redis.clientset.info.config.libname.suffix` |The clientset info configuration libname suffix attribute for the jedis client configuration with this configuration instance.
1567+
|===
15031568

1504-
|`jnosql.redis.min.idle`
1505-
|The value for the minIdle configuration attribute for pools created with this configuration instance, the default value 1.
1569+
==== Redis Sentinel Configuration
15061570

1507-
|`jnosql.redis.max.wait.millis`
1508-
|The value for the maxWait configuration attribute for pools created with this configuration instance, the default value 3000.
1571+
This API provides the `RedisSentinelConfigurations` class to programmatically establish the credentials.
1572+
Please note that you can establish properties using the https://microprofile.io/microprofile-config/[MicroProfile Config] specification.
15091573

1574+
[cols="2,2", options="header"]
1575+
|===
1576+
|Configuration Property |Description
1577+
1578+
|`jnosql.redis.sentinel.hosts` |The value for the sentinel HOST:PORT (separated by comma) configuration attribute for the jedis client configuration with this configuration instance.
1579+
|`jnosql.redis.sentinel.master.name` |The value for the master name configuration attribute for the jedis client configuration with this configuration instance.
1580+
|`jnosql.redis.sentinel.master.client.name` |The master client's name, the default value is 0
1581+
|`jnosql.redis.sentinel.slave.client.name` |The slave client's name, the default value is 0
1582+
|`jnosql.redis.sentinel.master.timeout` |The master redis timeout, the default value is 2000 milliseconds
1583+
|`jnosql.redis.sentinel.slave.timeout` |The slave redis timeout, the default value is 2000 milliseconds
1584+
|`jnosql.redis.sentinel.master.connection.timeout` |The connection timeout in milliseconds configuration attribute for the master jedis client configuration created with this configuration instance.
1585+
|`jnosql.redis.sentinel.slave.connection.timeout` |The connection timeout in milliseconds configuration attribute for the slave jedis client configuration created with this configuration instance.
1586+
|`jnosql.redis.sentinel.master.socket.timeout` |The socket timeout in milliseconds configuration attribute for the master jedis client configuration with this configuration instance.
1587+
|`jnosql.redis.sentinel.slave.socket.timeout` |The socket timeout in milliseconds configuration attribute for the slave jedis client configuration with this configuration instance.
1588+
|`jnosql.redis.sentinel.master.user` |The user configuration attribute for the master jedis client configuration with this configuration instance.
1589+
|`jnosql.redis.sentinel.slave.user` |The user configuration attribute for the slave jedis client configuration with this configuration instance.
1590+
|`jnosql.redis.sentinel.master.password` |The password configuration attribute for the master jedis client configuration with this configuration instance.
1591+
|`jnosql.redis.sentinel.slave.password` |The password configuration attribute for the slave jedis client configuration with this configuration instance.
1592+
|`jnosql.redis.sentinel.master.ssl` |The ssl configuration attribute for the master jedis client configuration with this configuration instance. The default value is false.
1593+
|`jnosql.redis.sentinel.slave.ssl` |The ssl configuration attribute for the slave jedis client configuration with this configuration instance. The default value is false.
1594+
|`jnosql.redis.sentinel.master.protocol` |The protocol configuration attribute for the master jedis client configuration with this configuration instance.
1595+
|`jnosql.redis.sentinel.slave.protocol` |The protocol configuration attribute for the slave jedis client configuration with this configuration instance.
1596+
|`jnosql.redis.sentinel.master.clientset.info.config.disabled` |The clientset info disabled configuration attribute for the master jedis client configuration with this configuration instance. The default value is false.
1597+
|`jnosql.redis.sentinel.slave.clientset.info.config.disabled` |The clientset info disabled configuration attribute for the slave jedis client configuration with this configuration instance. The default value is false.
1598+
|`jnosql.redis.sentinel.master.clientset.info.config.libname.suffix` |The clientset info configuration libname suffix attribute for the master jedis client configuration with this configuration instance.
1599+
|`jnosql.redis.sentinel.slave.clientset.info.config.libname.suffix` |The clientset info configuration libname suffix attribute for the slave jedis client configuration with this configuration instance.
15101600
|===
15111601

1512-
This is an example using Redis's Key-Value API with MicroProfile Config.
1602+
==== Redis Cluster Configuration
15131603

1514-
[source,properties]
1515-
----
1516-
jnosql.keyvalue.provider=org.eclipse.jnosql.databases.redis.communication.RedisConfiguration
1517-
jnosql.keyvalue.database=heroes
1518-
----
1604+
This API provides the `RedisClusterConfigurations` class to programmatically establish the credentials.
1605+
Please note that you can establish properties using the https://microprofile.io/microprofile-config/[MicroProfile Config] specification.
1606+
1607+
[cols="2,2", options="header"]
1608+
|===
1609+
|Configuration Property |Description
1610+
1611+
|`jnosql.redis.cluster.hosts` |The value for the sentinel HOST:PORT (separated by comma) configuration attribute for the jedis client configuration with this configuration instance.
1612+
|`jnosql.redis.cluster.client.name` |The cluster client's name. The default value is 0.
1613+
|`jnosql.redis.cluster.timeout` |The cluster redis timeout, the default value is 2000 milliseconds
1614+
|`jnosql.redis.cluster.connection.timeout` |The connection timeout in milliseconds configuration attribute for the cluster jedis client configuration created with this configuration instance.
1615+
|`jnosql.redis.cluster.socket.timeout` |The socket timeout in milliseconds configuration attribute for the cluster jedis client configuration with this configuration instance.
1616+
|`jnosql.redis.cluster.user` |The user configuration attribute for the cluster jedis client configuration with this configuration instance.
1617+
|`jnosql.redis.cluster.password` |The password configuration attribute for the cluster jedis client configuration with this configuration instance.
1618+
|`jnosql.redis.cluster.ssl` |The ssl configuration attribute for the cluster jedis client configuration with this configuration instance. The default value is false.
1619+
|`jnosql.redis.cluster.protocol` |The protocol configuration attribute for the cluster jedis client configuration with this configuration instance.
1620+
|`jnosql.redis.cluster.clientset.info.config.disabled` |The clientset info disabled configuration attribute for the cluster jedis client configuration with this configuration instance. The default value is false.
1621+
|`jnosql.redis.cluster.clientset.info.config.libname.suffix` |The clientset info configuration libname suffix attribute for the cluster jedis client configuration with this configuration instance.
1622+
|`jnosql.redis.cluster.max.attempts` |The value for the max attempts configuration attribute for the cluster jedis client configuration with this configuration instance. Default is 5.
1623+
|`jnosql.redis.cluster.max.total.retries.duration` |The value for the max total retries configuration attribute for the cluster jedis client configuration with this configuration instance. Default is 10000 milliseconds.
1624+
|===
15191625

15201626
=== RedisBucketManagerFactory
15211627

jnosql-redis/src/main/java/org/eclipse/jnosql/databases/redis/communication/Counter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
public interface Counter {
2424

2525
/**
26+
* Returns the counter value
27+
*
2628
* @return The counter value
2729
*/
2830
Number get();

jnosql-redis/src/main/java/org/eclipse/jnosql/databases/redis/communication/DefaultCounter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
package org.eclipse.jnosql.databases.redis.communication;
1616

17-
import redis.clients.jedis.Jedis;
17+
import redis.clients.jedis.UnifiedJedis;
1818

1919
import java.time.Duration;
2020
import java.util.Objects;
@@ -32,14 +32,13 @@ class DefaultCounter implements Counter {
3232

3333
private final String key;
3434

35-
private Jedis jedis;
35+
private final UnifiedJedis jedis;
3636

37-
DefaultCounter(String key, Jedis jedis) {
37+
DefaultCounter(String key, UnifiedJedis jedis) {
3838
this.key = key;
3939
this.jedis = jedis;
4040
}
4141

42-
4342
@Override
4443
public Number get() {
4544
return Optional.ofNullable(jedis.get(key))

jnosql-redis/src/main/java/org/eclipse/jnosql/databases/redis/communication/DefaultRedisBucketManagerFactory.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import jakarta.json.bind.Jsonb;
1818
import org.eclipse.jnosql.communication.driver.JsonbSupplier;
19-
import redis.clients.jedis.JedisPool;
19+
import redis.clients.jedis.UnifiedJedis;
2020

2121
import java.util.List;
2222
import java.util.Map;
@@ -29,70 +29,70 @@ class DefaultRedisBucketManagerFactory implements RedisBucketManagerFactory {
2929

3030
private static final Jsonb JSON = JsonbSupplier.getInstance().get();
3131

32-
private final JedisPool jedisPool;
32+
private final UnifiedJedis jedis;
3333

34-
DefaultRedisBucketManagerFactory(JedisPool jedisPool) {
35-
this.jedisPool = jedisPool;
34+
DefaultRedisBucketManagerFactory(UnifiedJedis jedis) {
35+
this.jedis = jedis;
3636
}
3737

3838

3939
@Override
4040
public RedisBucketManager apply(String bucketName) {
4141
requireNonNull(bucketName, "bucket name is required");
4242

43-
return new RedisBucketManager(bucketName, JSON, jedisPool.getResource());
43+
return new RedisBucketManager(bucketName, JSON, jedis);
4444
}
4545

4646
@Override
4747
public <T> List<T> getList(String bucketName, Class<T> clazz) {
4848
requireNonNull(bucketName, "bucket name is required");
4949
requireNonNull(clazz, "Class type is required");
50-
return new RedisList<>(jedisPool.getResource(), clazz, bucketName);
50+
return new RedisList<>(jedis, clazz, bucketName);
5151
}
5252

5353
@Override
5454
public <T> Set<T> getSet(String bucketName, Class<T> clazz) {
5555
requireNonNull(bucketName, "bucket name is required");
5656
requireNonNull(clazz, "Class type is required");
57-
return new RedisSet<>(jedisPool.getResource(), clazz, bucketName);
57+
return new RedisSet<>(jedis, clazz, bucketName);
5858
}
5959

6060
@Override
6161
public <T> Queue<T> getQueue(String bucketName, Class<T> clazz) {
6262
requireNonNull(bucketName, "bucket name is required");
6363
requireNonNull(clazz, "Class type is required");
64-
return new RedisQueue<>(jedisPool.getResource(), clazz, bucketName);
64+
return new RedisQueue<>(jedis, clazz, bucketName);
6565
}
6666

6767
@Override
6868
public <K, V> Map<K, V> getMap(String bucketName, Class<K> keyValue, Class<V> valueValue) {
6969
requireNonNull(bucketName, "bucket name is required");
7070
requireNonNull(valueValue, "Class type is required");
71-
return new RedisMap<>(jedisPool.getResource(), keyValue, valueValue, bucketName);
71+
return new RedisMap<>(jedis, keyValue, valueValue, bucketName);
7272
}
7373

7474
@Override
7575
public SortedSet getSortedSet(String key) throws NullPointerException {
7676
requireNonNull(key, "key is required");
77-
return new DefaultSortedSet(jedisPool.getResource(), key);
77+
return new DefaultSortedSet(jedis, key);
7878
}
7979

8080
@Override
8181
public Counter getCounter(String key) throws NullPointerException {
8282
requireNonNull(key, "key is required");
83-
return new DefaultCounter(key, jedisPool.getResource());
83+
return new DefaultCounter(key, jedis);
8484
}
8585

8686

8787
@Override
8888
public void close() {
89-
jedisPool.close();
89+
jedis.close();
9090
}
9191

9292
@Override
9393
public String toString() {
9494
final StringBuilder sb = new StringBuilder("RedisBucketManagerFactory{");
95-
sb.append("jedisPool=").append(jedisPool);
95+
sb.append("jedisPool=").append(jedis);
9696
sb.append('}');
9797
return sb.toString();
9898
}

jnosql-redis/src/main/java/org/eclipse/jnosql/databases/redis/communication/DefaultSortedSet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.eclipse.jnosql.databases.redis.communication;
1717

1818

19-
import redis.clients.jedis.Jedis;
19+
import redis.clients.jedis.UnifiedJedis;
2020

2121
import java.time.Duration;
2222
import java.util.List;
@@ -33,9 +33,9 @@ class DefaultSortedSet implements SortedSet {
3333
private static final int LAST_ELEMENT = -1;
3434
private String key;
3535

36-
private Jedis jedis;
36+
private UnifiedJedis jedis;
3737

38-
DefaultSortedSet(Jedis jedis, String keyspace) {
38+
DefaultSortedSet(UnifiedJedis jedis, String keyspace) {
3939
Objects.requireNonNull(jedis, "jedis is required");
4040
Objects.requireNonNull(keyspace, "keyspace is required");
4141
this.key = keyspace;

jnosql-redis/src/main/java/org/eclipse/jnosql/databases/redis/communication/RedisBucketManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.eclipse.jnosql.communication.driver.ValueJSON;
2222
import org.eclipse.jnosql.communication.keyvalue.BucketManager;
2323
import org.eclipse.jnosql.communication.keyvalue.KeyValueEntity;
24-
import redis.clients.jedis.Jedis;
24+
import redis.clients.jedis.UnifiedJedis;
2525

2626
import java.time.Duration;
2727
import java.util.Objects;
@@ -38,9 +38,9 @@ public class RedisBucketManager implements BucketManager {
3838
private final String nameSpace;
3939
private final Jsonb jsonB;
4040

41-
private final Jedis jedis;
41+
private final UnifiedJedis jedis;
4242

43-
RedisBucketManager(String nameSpace, Jsonb provider, Jedis jedis) {
43+
RedisBucketManager(String nameSpace, Jsonb provider, UnifiedJedis jedis) {
4444
this.nameSpace = nameSpace;
4545
this.jsonB = provider;
4646
this.jedis = jedis;

0 commit comments

Comments
 (0)