Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JNoSQL Redis Database API] - Fixed broken connection issue and added sentinel and cluster support #297

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version

== [Unreleased]

=== Added
- Added Redis Sentinel and Redis Cluster configuration at JNoSQL Redis Database API

=== Fixed
- Fixed the broken connection issue at JNoSQL Redis Database API

== [1.1.2] - 2023-09-15

=== Added
Expand Down
166 changes: 136 additions & 30 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1470,52 +1470,158 @@ You can use either the Maven or Gradle dependencies:

=== Configuration

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

[cols="Redis"]
|===
|Configuration property |Description
[source,properties]
----
jnosql.keyvalue.provider=org.eclipse.jnosql.databases.redis.communication.RedisConfiguration
jnosql.keyvalue.database=heroes
----

|`jnosql.redis.host`
|The database host
This API provides enum classes to programmatically establish the credentials as:

|`jnosql.redis.port`
|The database port
- link:README.adoc#_single_node_configuration[`RedisConfigurations`] for single node configuration
+
[source,properties]
----
# Single Node Configuration

|`jnosql.redis.timeout`
|The redis timeout, the default value 2000 on milliseconds
# by default the host is localhost
jnosql.redis.host=localhost
# by default the port is 6379
jnosql.redis.port=6379
# if you have user
jnosql.redis.user=youruser
# if you have password
jnosql.redis.password=yourpassword
----

|`jnosql.redis.password`
|The user's password
- link:README.adoc#_redis_sentinel_configuration[`RedisSentinelConfigurations`] for sentinel configuration
+
[source,properties]
----
# Sentinel Configuration
jnosql.redis.sentinel.hosts=host1:26379,host2:26379

jnosql.redis.sentinel.master.name=masterName
jnosql.redis.sentinel.master.user=masterUser
jnosql.redis.sentinel.master.password=masterPassword
#jnosql.redis.sentinel.master.ssl=false
#jnosql.redis.sentinel.master.timeout=2000
#jnosql.redis.sentinel.master.connection.timeout=2000
#jnosql.redis.sentinel.master.socket.timeout=2000

jnosql.redis.sentinel.slave.user=slaveUser
jnosql.redis.sentinel.slave.password=slavePassword
#jnosql.redis.sentinel.slave.ssl=false
#jnosql.redis.sentinel.slave.timeout=2000
#jnosql.redis.sentinel.slave.connection.timeout=2000
#jnosql.redis.sentinel.slave.socket.timeout=2000
----

- link:README.adoc#_redis_sentinel_configuration[`RedisClusterConfigurations`] for cluster configuration
+
[source,properties]
----
# Cluster Configuration

|`jnosql.redis.database`
|The redis database number, the default value is 0
jnosql.redis.cluster.hosts=host1:6379,host2:6379
jnosql.redis.cluster.user=clusterUser
jnosql.redis.cluster.password=clusterPassword
jnosql.redis.cluster.client.name=clusterClientName
jnosql.redis.cluster.max.attempts=5
jnosql.redis.cluster.max.total.retries.duration=10000
#jnosql.redis.cluster.ssl=false
#jnosql.redis.cluster.timeout=2000
#jnosql.redis.cluster.connection.timeout=2000
#jnosql.redis.cluster.socket.timeout=2000
----

|`jnosql.redis.client.name`
|The client's name
==== Single Node Configuration

This API provides the `RedisConfigurations` class to programmatically establish the credentials.
Please note that you can establish properties using the https://microprofile.io/microprofile-config/[MicroProfile Config] specification.

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

|`jnosql.redis.max.idle`
|The value for the maxIdle configuration attribute for pools created with this configuration instance, the default value 10.
|`jnosql.redis.host` |The database host
|`jnosql.redis.port` |The database port
|`jnosql.redis.timeout` |The redis timeout, the default value is 2000 milliseconds
|`jnosql.redis.password` |The password's credential
|`jnosql.redis.database` |The redis database number
|`jnosql.redis.client.name` |The cluster client's name. The default value is 0.
|`jnosql.redis.max.total` |The value for the maxTotal configuration attribute for pools created with this configuration instance. The default value is 1000.
|`jnosql.redis.max.idle` |The value for the maxIdle configuration attribute for pools created with this configuration instance. The default value is 10.
|`jnosql.redis.min.idle` |The value for the minIdle configuration attribute for pools created with this configuration instance. The default value is 1.
|`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.
|`jnosql.redis.connection.timeout` |The connection timeout in milliseconds configuration attribute for the jedis client configuration created with this configuration instance.
|`jnosql.redis.socket.timeout` |The socket timeout in milliseconds configuration attribute for the jedis client configuration with this configuration instance.
|`jnosql.redis.user` |The user configuration attribute for the jedis client configuration with this configuration instance.
|`jnosql.redis.ssl` |The ssl configuration attribute for the jedis client configuration with this configuration instance. The default value is false.
|`jnosql.redis.protocol` |The protocol configuration attribute for the jedis client configuration with this configuration instance.
|`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.
|`jnosql.redis.clientset.info.config.libname.suffix` |The clientset info configuration libname suffix attribute for the jedis client configuration with this configuration instance.
|===

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

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

[cols="2,2", options="header"]
|===
|Configuration Property |Description

|`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.
|`jnosql.redis.sentinel.master.name` |The value for the master name configuration attribute for the jedis client configuration with this configuration instance.
|`jnosql.redis.sentinel.master.client.name` |The master client's name, the default value is 0
|`jnosql.redis.sentinel.slave.client.name` |The slave client's name, the default value is 0
|`jnosql.redis.sentinel.master.timeout` |The master redis timeout, the default value is 2000 milliseconds
|`jnosql.redis.sentinel.slave.timeout` |The slave redis timeout, the default value is 2000 milliseconds
|`jnosql.redis.sentinel.master.connection.timeout` |The connection timeout in milliseconds configuration attribute for the master jedis client configuration created with this configuration instance.
|`jnosql.redis.sentinel.slave.connection.timeout` |The connection timeout in milliseconds configuration attribute for the slave jedis client configuration created with this configuration instance.
|`jnosql.redis.sentinel.master.socket.timeout` |The socket timeout in milliseconds configuration attribute for the master jedis client configuration with this configuration instance.
|`jnosql.redis.sentinel.slave.socket.timeout` |The socket timeout in milliseconds configuration attribute for the slave jedis client configuration with this configuration instance.
|`jnosql.redis.sentinel.master.user` |The user configuration attribute for the master jedis client configuration with this configuration instance.
|`jnosql.redis.sentinel.slave.user` |The user configuration attribute for the slave jedis client configuration with this configuration instance.
|`jnosql.redis.sentinel.master.password` |The password configuration attribute for the master jedis client configuration with this configuration instance.
|`jnosql.redis.sentinel.slave.password` |The password configuration attribute for the slave jedis client configuration with this configuration instance.
|`jnosql.redis.sentinel.master.ssl` |The ssl configuration attribute for the master jedis client configuration with this configuration instance. The default value is false.
|`jnosql.redis.sentinel.slave.ssl` |The ssl configuration attribute for the slave jedis client configuration with this configuration instance. The default value is false.
|`jnosql.redis.sentinel.master.protocol` |The protocol configuration attribute for the master jedis client configuration with this configuration instance.
|`jnosql.redis.sentinel.slave.protocol` |The protocol configuration attribute for the slave jedis client configuration with this configuration instance.
|`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.
|`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.
|`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.
|`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.
|===

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

[source,properties]
----
jnosql.keyvalue.provider=org.eclipse.jnosql.databases.redis.communication.RedisConfiguration
jnosql.keyvalue.database=heroes
----
This API provides the `RedisClusterConfigurations` class to programmatically establish the credentials.
Please note that you can establish properties using the https://microprofile.io/microprofile-config/[MicroProfile Config] specification.

[cols="2,2", options="header"]
|===
|Configuration Property |Description

|`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.
|`jnosql.redis.cluster.client.name` |The cluster client's name. The default value is 0.
|`jnosql.redis.cluster.timeout` |The cluster redis timeout, the default value is 2000 milliseconds
|`jnosql.redis.cluster.connection.timeout` |The connection timeout in milliseconds configuration attribute for the cluster jedis client configuration created with this configuration instance.
|`jnosql.redis.cluster.socket.timeout` |The socket timeout in milliseconds configuration attribute for the cluster jedis client configuration with this configuration instance.
|`jnosql.redis.cluster.user` |The user configuration attribute for the cluster jedis client configuration with this configuration instance.
|`jnosql.redis.cluster.password` |The password configuration attribute for the cluster jedis client configuration with this configuration instance.
|`jnosql.redis.cluster.ssl` |The ssl configuration attribute for the cluster jedis client configuration with this configuration instance. The default value is false.
|`jnosql.redis.cluster.protocol` |The protocol configuration attribute for the cluster jedis client configuration with this configuration instance.
|`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.
|`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.
|`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.
|`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.
|===

=== RedisBucketManagerFactory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
public interface Counter {

/**
* Returns the counter value
*
* @return The counter value
*/
Number get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.eclipse.jnosql.databases.redis.communication;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.UnifiedJedis;

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

private final String key;

private Jedis jedis;
private final UnifiedJedis jedis;

DefaultCounter(String key, Jedis jedis) {
DefaultCounter(String key, UnifiedJedis jedis) {
this.key = key;
this.jedis = jedis;
}


@Override
public Number get() {
return Optional.ofNullable(jedis.get(key))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import jakarta.json.bind.Jsonb;
import org.eclipse.jnosql.communication.driver.JsonbSupplier;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.UnifiedJedis;

import java.util.List;
import java.util.Map;
Expand All @@ -29,70 +29,70 @@ class DefaultRedisBucketManagerFactory implements RedisBucketManagerFactory {

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

private final JedisPool jedisPool;
private final UnifiedJedis jedis;

DefaultRedisBucketManagerFactory(JedisPool jedisPool) {
this.jedisPool = jedisPool;
DefaultRedisBucketManagerFactory(UnifiedJedis jedis) {
this.jedis = jedis;
}


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

return new RedisBucketManager(bucketName, JSON, jedisPool.getResource());
return new RedisBucketManager(bucketName, JSON, jedis);
}

@Override
public <T> List<T> getList(String bucketName, Class<T> clazz) {
requireNonNull(bucketName, "bucket name is required");
requireNonNull(clazz, "Class type is required");
return new RedisList<>(jedisPool.getResource(), clazz, bucketName);
return new RedisList<>(jedis, clazz, bucketName);
}

@Override
public <T> Set<T> getSet(String bucketName, Class<T> clazz) {
requireNonNull(bucketName, "bucket name is required");
requireNonNull(clazz, "Class type is required");
return new RedisSet<>(jedisPool.getResource(), clazz, bucketName);
return new RedisSet<>(jedis, clazz, bucketName);
}

@Override
public <T> Queue<T> getQueue(String bucketName, Class<T> clazz) {
requireNonNull(bucketName, "bucket name is required");
requireNonNull(clazz, "Class type is required");
return new RedisQueue<>(jedisPool.getResource(), clazz, bucketName);
return new RedisQueue<>(jedis, clazz, bucketName);
}

@Override
public <K, V> Map<K, V> getMap(String bucketName, Class<K> keyValue, Class<V> valueValue) {
requireNonNull(bucketName, "bucket name is required");
requireNonNull(valueValue, "Class type is required");
return new RedisMap<>(jedisPool.getResource(), keyValue, valueValue, bucketName);
return new RedisMap<>(jedis, keyValue, valueValue, bucketName);
}

@Override
public SortedSet getSortedSet(String key) throws NullPointerException {
requireNonNull(key, "key is required");
return new DefaultSortedSet(jedisPool.getResource(), key);
return new DefaultSortedSet(jedis, key);
}

@Override
public Counter getCounter(String key) throws NullPointerException {
requireNonNull(key, "key is required");
return new DefaultCounter(key, jedisPool.getResource());
return new DefaultCounter(key, jedis);
}


@Override
public void close() {
jedisPool.close();
jedis.close();
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("RedisBucketManagerFactory{");
sb.append("jedisPool=").append(jedisPool);
sb.append("jedisPool=").append(jedis);
sb.append('}');
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.eclipse.jnosql.databases.redis.communication;


import redis.clients.jedis.Jedis;
import redis.clients.jedis.UnifiedJedis;

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

private Jedis jedis;
private UnifiedJedis jedis;

DefaultSortedSet(Jedis jedis, String keyspace) {
DefaultSortedSet(UnifiedJedis jedis, String keyspace) {
Objects.requireNonNull(jedis, "jedis is required");
Objects.requireNonNull(keyspace, "keyspace is required");
this.key = keyspace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.jnosql.communication.driver.ValueJSON;
import org.eclipse.jnosql.communication.keyvalue.BucketManager;
import org.eclipse.jnosql.communication.keyvalue.KeyValueEntity;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.UnifiedJedis;

import java.time.Duration;
import java.util.Objects;
Expand All @@ -38,9 +38,9 @@ public class RedisBucketManager implements BucketManager {
private final String nameSpace;
private final Jsonb jsonB;

private final Jedis jedis;
private final UnifiedJedis jedis;

RedisBucketManager(String nameSpace, Jsonb provider, Jedis jedis) {
RedisBucketManager(String nameSpace, Jsonb provider, UnifiedJedis jedis) {
this.nameSpace = nameSpace;
this.jsonB = provider;
this.jedis = jedis;
Expand Down
Loading