Skip to content

Commit

Permalink
chore(core): Redis Improvements #26932 (#26974)
Browse files Browse the repository at this point in the history
* #26932 fixes for redis

* #26932 now works locally

* #26932 fixing a test issue

---------

Co-authored-by: Freddy Montes <751424+fmontes@users.noreply.github.com>
  • Loading branch information
jdotcms and fmontes committed Feb 5, 2024
1 parent 49683b9 commit 345d6ed
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 263 deletions.
Expand Up @@ -59,6 +59,8 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static io.lettuce.core.ScriptOutputType.STATUS;

/**
* Master replica implementation of redis cache. It works as a replicator when there is more than 1 URIs as part of the
* {@code REDIS_LETTUCECLIENT_URLS} config. This implementation wraps keys, members and channels by prefixing them with
Expand Down Expand Up @@ -152,7 +154,7 @@ protected List<RedisURI> createRedisConnection() {
.map(RedisURI::create)
.collect(Collectors.toList());
}
final String redisSessionEnabled = envVarService.getenv().getOrDefault("TOMCAT_REDIS_SESSION_ENABLED", "false");
final String redisSessionEnabled = envVarService.getenv().getOrDefault("TOMCAT_REDIS_SESSION_ENABLED", "false");
if (Boolean.parseBoolean(redisSessionEnabled)) {
final RedisURI redisURI = RedisURI.builder()
.withHost(envVarService.getenv().getOrDefault("TOMCAT_REDIS_SESSION_HOST", "localhost"))
Expand All @@ -164,7 +166,7 @@ protected List<RedisURI> createRedisConnection() {
.build();
return List.of(redisURI);
}
return List.of(RedisURI.create("redis://password@oboxturbo"));
return List.of(RedisURI.create("redis://localhost"));
}

/**
Expand Down Expand Up @@ -900,6 +902,19 @@ public Collection<K> getChannels() {
return channelReferenceMap.keySet().stream().map(this::unwrapKey).collect(Collectors.toList());
}

@Override
public void deleteFromPattern(final String pattern) {

try (StatefulRedisConnection<String,V> conn = this.getConn()) {

if (this.isOpen(conn)) {

conn.async().eval("return redis.call('del', unpack(redis.call('keys', '" + pattern + "')))",
STATUS, new String[0]);
}
}
}

@Override
public Future<Long> publishMessage (final V message, final K channelIn) {

Expand Down
Expand Up @@ -170,6 +170,11 @@ public long getIncrement (final Object key) {
return -1;
}

@Override
public void deleteFromPattern(String pattern) {

}


@Override
public void scanKeys(String matchesPattern, int keyBatchingSize, Consumer keyConsumer) {
Expand Down

0 comments on commit 345d6ed

Please sign in to comment.