Fixed - Hibernate region_prefix configuration doesn't apply to redis key redisson-hibernate-timestamp

Signed-off-by: seakider <seakider@gmail.com>
pull/6474/head
seakider 7 days ago
parent 5f95893464
commit 9141c12690

@ -19,6 +19,7 @@ import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.*;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.Settings;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.jboss.logging.Logger;
import org.redisson.Redisson;
@ -168,7 +169,7 @@ public class RedissonRegionFactory implements RegionFactory {
+ "local nextValue = math.max(tonumber(ARGV[1]), tonumber(currentTime) + 1); "
+ "redis.call('set', KEYS[1], nextValue); "
+ "return nextValue;",
RScript.ReturnType.INTEGER, Collections.singletonList("redisson-hibernate-timestamp"), time);
RScript.ReturnType.INTEGER, Collections.singletonList(qualifyName("redisson-hibernate-timestamp")), time);
} catch (Exception e) {
if (fallback) {
while (true) {
@ -189,6 +190,14 @@ public class RedissonRegionFactory implements RegionFactory {
}
}
private String qualifyName(String name) {
String prefix = settings.getCacheRegionPrefix();
if (StringHelper.isEmpty(prefix)) {
return name;
}
return prefix + "." + name;
}
@Override
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata)
throws CacheException {

@ -22,6 +22,7 @@ import org.hibernate.cache.spi.*;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Settings;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.jboss.logging.Logger;
import org.redisson.Redisson;
@ -175,7 +176,7 @@ import java.util.concurrent.atomic.AtomicLong;
+ "local nextValue = math.max(tonumber(ARGV[1]), tonumber(currentTime) + 1); "
+ "redis.call('set', KEYS[1], nextValue); "
+ "return nextValue;",
RScript.ReturnType.INTEGER, Collections.singletonList("redisson-hibernate-timestamp"), time);
RScript.ReturnType.INTEGER, Collections.singletonList(qualifyName("redisson-hibernate-timestamp")), time);
} catch (Exception e) {
if (fallback) {
while (true) {
@ -196,6 +197,14 @@ import java.util.concurrent.atomic.AtomicLong;
}
}
private String qualifyName(String name) {
String prefix = settings.getCacheRegionPrefix();
if (StringHelper.isEmpty(prefix)) {
return name;
}
return prefix + "." + name;
}
@Override
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata)
throws CacheException {

@ -22,6 +22,7 @@ import org.hibernate.cache.spi.*;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Settings;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.jboss.logging.Logger;
import org.redisson.Redisson;
@ -176,7 +177,7 @@ public class RedissonRegionFactory implements RegionFactory {
+ "local nextValue = math.max(tonumber(ARGV[1]), tonumber(currentTime) + 1); "
+ "redis.call('set', KEYS[1], nextValue); "
+ "return nextValue;",
RScript.ReturnType.INTEGER, Collections.singletonList("redisson-hibernate-timestamp"), time);
RScript.ReturnType.INTEGER, Collections.singletonList(qualifyName("redisson-hibernate-timestamp")), time);
} catch (Exception e) {
if (fallback) {
while (true) {
@ -197,6 +198,14 @@ public class RedissonRegionFactory implements RegionFactory {
}
}
private String qualifyName(String name) {
String prefix = settings.getCacheRegionPrefix();
if (StringHelper.isEmpty(prefix)) {
return name;
}
return prefix + "." + name;
}
@Override
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata)
throws CacheException {

@ -176,7 +176,7 @@ public class RedissonRegionFactory extends RegionFactoryTemplate {
+ "local nextValue = math.max(tonumber(ARGV[1]), tonumber(currentTime) + 1); "
+ "redis.call('set', KEYS[1], nextValue); "
+ "return nextValue;",
RScript.ReturnType.INTEGER, Arrays.<Object>asList("redisson-hibernate-timestamp"), time);
RScript.ReturnType.INTEGER, Arrays.<Object>asList(qualifyName("redisson-hibernate-timestamp")), time);
} catch (Exception e) {
if (fallback) {
return super.nextTimestamp();

@ -177,7 +177,7 @@ public class RedissonRegionFactory extends RegionFactoryTemplate {
+ "local nextValue = math.max(tonumber(ARGV[1]), tonumber(currentTime) + 1); "
+ "redis.call('set', KEYS[1], nextValue); "
+ "return nextValue;",
RScript.ReturnType.INTEGER, Arrays.<Object>asList("redisson-hibernate-timestamp"), time);
RScript.ReturnType.INTEGER, Arrays.<Object>asList(qualifyName("redisson-hibernate-timestamp")), time);
} catch (Exception e) {
if (fallback) {
return super.nextTimestamp();

Loading…
Cancel
Save