-
Notifications
You must be signed in to change notification settings - Fork 4
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
Added support for redis clustered mode #735
Draft
munishchouhan
wants to merge
7
commits into
master
Choose a base branch
from
714-enhancement-redis-support-clustered-mode
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3294a57
added RedisService
munishchouhan 12999cf
added RedisService
munishchouhan f200972
Merge branch 'master' into 714-enhancement-redis-support-clustered-mode
munishchouhan 31640e4
added mode in redis profile
munishchouhan 31f90bd
Revert "added mode in redis profile"
munishchouhan 3386c3b
set standalone as default
munishchouhan 879c049
Merge branch 'master' into 714-enhancement-redis-support-clustered-mode
munishchouhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Wave, containers provisioning service | ||
* Copyright (c) 2023-2024, Seqera Labs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.seqera.wave.redis | ||
|
||
import java.util.concurrent.TimeoutException | ||
|
||
import redis.clients.jedis.Connection | ||
import redis.clients.jedis.StreamEntryID | ||
import redis.clients.jedis.Transaction | ||
import redis.clients.jedis.params.ScanParams | ||
import redis.clients.jedis.params.SetParams | ||
import redis.clients.jedis.params.XAutoClaimParams | ||
import redis.clients.jedis.params.XReadGroupParams | ||
import redis.clients.jedis.resps.ScanResult | ||
import redis.clients.jedis.resps.StreamEntry | ||
import redis.clients.jedis.resps.Tuple | ||
/** | ||
* Implements RedisService | ||
* | ||
* @author Munish Chouhan <munish.chouhan@seqera.io> | ||
*/ | ||
interface RedisService { | ||
|
||
String get(final String key) | ||
|
||
long hincrBy(final String key, final String field, final long value) | ||
|
||
Long hget(final String key, final String field) | ||
|
||
ScanResult<Map.Entry<String, String>> hscan(String key, String cursor, ScanParams params) | ||
|
||
String set(final String key, final String value, final SetParams params) | ||
|
||
Transaction multi() throws TimeoutException | ||
|
||
long lpush(final String target, final String message) | ||
|
||
String rpop(final String target) | ||
|
||
String brpop( final double timeout, final String target) | ||
|
||
String xgroupCreate(final String key, final String groupName, final StreamEntryID id, final boolean makeStream) | ||
|
||
StreamEntryID xadd(final String key, final StreamEntryID id, final Map<String, String> hash) | ||
|
||
Map.Entry<StreamEntryID, List<StreamEntry>> xautoclaim(String key, String group, String consumerName, long minIdleTime, StreamEntryID start, XAutoClaimParams params) | ||
|
||
List<Map.Entry<String, List<StreamEntry>>> xreadGroup(final String groupName, final String consumer, final XReadGroupParams xReadGroupParams, final Map<String, StreamEntryID> streams) | ||
|
||
long zadd(final String key, final double score, final String member) | ||
|
||
Object eval(final String script, final int keyCount, final String... params) | ||
|
||
List<Tuple> zrangeByScoreWithScores(final String key, final double min, final double max, final int offset, final int count) | ||
|
||
long del(final String key) | ||
|
||
String flushAll() | ||
|
||
} |
125 changes: 125 additions & 0 deletions
125
src/main/groovy/io/seqera/wave/redis/impl/RedisServiceClusterImpl.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package io.seqera.wave.redis.impl | ||
|
||
import java.util.concurrent.TimeoutException | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.util.logging.Slf4j | ||
import io.micronaut.context.annotation.Requires | ||
import io.seqera.wave.redis.RedisService | ||
import jakarta.inject.Inject | ||
import jakarta.inject.Singleton | ||
import redis.clients.jedis.JedisCluster | ||
import redis.clients.jedis.StreamEntryID | ||
import redis.clients.jedis.Transaction | ||
import redis.clients.jedis.params.ScanParams | ||
import redis.clients.jedis.params.SetParams | ||
import redis.clients.jedis.params.XAutoClaimParams | ||
import redis.clients.jedis.params.XReadGroupParams | ||
import redis.clients.jedis.resps.ScanResult | ||
import redis.clients.jedis.resps.StreamEntry | ||
import redis.clients.jedis.resps.Tuple | ||
/** | ||
* Implements RedisService for redis cluster | ||
* | ||
* @author Munish Chouhan <munish.chouhan@seqera.io> | ||
*/ | ||
@Slf4j | ||
@Singleton | ||
@Requires(property = 'redis.uri') | ||
@Requires(property = "redis.mode", value = "cluster") | ||
@CompileStatic | ||
class RedisServiceClusterImpl implements RedisService { | ||
|
||
@Inject | ||
private JedisCluster cluster | ||
|
||
@Override | ||
String get(String key) { | ||
return cluster.get(key) | ||
} | ||
|
||
@Override | ||
long hincrBy(String key, String field, long value) { | ||
return cluster.hincrBy(key, field, value) | ||
} | ||
|
||
@Override | ||
Long hget(String key, String field) { | ||
return cluster.hget(key, field) ? cluster.hget(key, field).toLong() : null | ||
} | ||
|
||
@Override | ||
ScanResult<Map.Entry<String, String>> hscan(String key, String cursor, ScanParams params) { | ||
return cluster.hscan(key, cursor, params) | ||
} | ||
|
||
@Override | ||
String set(String key, String value, SetParams params) { | ||
return cluster.set(key, value, params) | ||
} | ||
|
||
@Override | ||
Transaction multi() throws TimeoutException { | ||
return cluster.multi() | ||
} | ||
|
||
@Override | ||
long lpush(String target, String message) { | ||
return cluster.lpush(target, message) | ||
} | ||
|
||
@Override | ||
String rpop(String target) { | ||
return cluster.rpop(target) | ||
} | ||
|
||
@Override | ||
String brpop(double timeout, String target) { | ||
return cluster.brpop(timeout, target) | ||
} | ||
|
||
@Override | ||
String xgroupCreate(String key, String groupName, StreamEntryID id, boolean makeStream) { | ||
return cluster.xgroupCreate(key, groupName, id, makeStream) | ||
} | ||
|
||
@Override | ||
StreamEntryID xadd(String key, StreamEntryID id, Map<String, String> hash) { | ||
return cluster.xadd(key, id, hash) | ||
} | ||
|
||
@Override | ||
Map.Entry<StreamEntryID, List<StreamEntry>> xautoclaim(String key, String group, String consumerName, long minIdleTime, StreamEntryID start, XAutoClaimParams params) { | ||
return cluster.xautoclaim(key, group, consumerName, minIdleTime, start, params) | ||
} | ||
|
||
@Override | ||
List<Map.Entry<String, List<StreamEntry>>> xreadGroup(String groupName, String consumer, XReadGroupParams xReadGroupParams, Map<String, StreamEntryID> streams) { | ||
return cluster.xreadGroup(groupName, consumer, xReadGroupParams, streams) | ||
} | ||
|
||
@Override | ||
long zadd(String key, double score, String member) { | ||
return cluster.zadd(key, score, member) | ||
} | ||
|
||
@Override | ||
Object eval(String script, int keyCount, String... params) { | ||
return cluster.eval(script, keyCount, params) | ||
} | ||
|
||
@Override | ||
List<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { | ||
return cluster.zrangeByScoreWithScores(key, min, max, offset, count) | ||
} | ||
|
||
@Override | ||
long del(String key) { | ||
return cluster.del(key) | ||
} | ||
|
||
@Override | ||
String flushAll() { | ||
return cluster.flushAll() | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure to understand the need for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JedisCluster and JedisPool doesnot have common Interface, so not possible to inject
Thats why I have created this service which have separate implementation for cluster and standalone and based on redis.mode it will be initialized