Skip to content

Commit 7f9c660

Browse files
author
李金松
committed
Implemented read-write separation based on JedisSentineled
1 parent ed87b5e commit 7f9c660

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/main/java/redis/clients/jedis/Protocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public final class Protocol {
2323

2424
public static final String DEFAULT_HOST = "127.0.0.1";
2525
public static final int DEFAULT_PORT = 6379;
26-
public static final int DEFAULT_SENTINEL_PORT = 26379;
26+
public static final int DEFAULT_SENTINEL_PORT = 26378;
2727
public static final int DEFAULT_TIMEOUT = 2000;
2828
public static final int DEFAULT_DATABASE = 0;
2929
public static final int CLUSTER_HASHSLOTS = 16384;

src/test/java/redis/clients/jedis/HostAndPorts.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public final class HostAndPorts {
2121
}
2222

2323
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT));
24-
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 1));
24+
sentinelHostAndPortList.add(new HostAndPort("10.148.17.43", Protocol.DEFAULT_SENTINEL_PORT + 1));
2525
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 2));
26-
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 3));
26+
sentinelHostAndPortList.add(new HostAndPort("10.148.17.43", Protocol.DEFAULT_SENTINEL_PORT + 3));
2727
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 4));
2828

2929
clusterHostAndPortList.add(new HostAndPort("localhost", 7379));

src/test/java/redis/clients/jedis/csc/JedisSentineledClientSideCacheTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class JedisSentineledClientSideCacheTest extends UnifiedJedisClientSideCa
2525

2626
private static final Set<HostAndPort> sentinels = new HashSet<>(Arrays.asList(sentinel1, sentinel2));
2727

28-
private static final JedisClientConfig masterClientConfig = DefaultJedisClientConfig.builder().resp3().password("foobared").build();
28+
private static final JedisClientConfig masterClientConfig = DefaultJedisClientConfig.builder().resp3().password("0a2eb141353cf115").build();
2929

3030
private static final JedisClientConfig sentinelClientConfig = DefaultJedisClientConfig.builder().resp3().build();
3131

@@ -43,8 +43,8 @@ protected JedisSentineled createCachedJedis(CacheConfig cacheConfig) {
4343
public static void prepare() {
4444
try (JedisSentineled sentinelClient = new JedisSentineled(MASTER_NAME, masterClientConfig, sentinels, sentinelClientConfig);
4545
Jedis master = new Jedis(sentinelClient.getCurrentMaster(),masterClientConfig)) {
46-
assumeTrue(RedisVersionUtil.getRedisVersion(master).isGreaterThanOrEqualTo(RedisVersion.V7_4),
47-
"Jedis Client side caching is only supported with 'Redis 7.4' or later.");
46+
// assumeTrue(RedisVersionUtil.getRedisVersion(master).isGreaterThanOrEqualTo(RedisVersion.V7_4),
47+
// "Jedis Client side caching is only supported with 'Redis 7.4' or later.");
4848
}
4949
}
5050
}

src/test/java/redis/clients/jedis/csc/UnifiedJedisClientSideCacheTestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void immutableCacheEntriesTest() {
145145
}
146146

147147
@Test
148-
public void invalidationTest() {
148+
public void invalidationTest() throws InterruptedException {
149149
try (UnifiedJedis jedis = createCachedJedis(CacheConfig.builder().build())) {
150150
Cache cache = jedis.getCache();
151151
jedis.set("{csc}1", "one");
@@ -161,6 +161,7 @@ public void invalidationTest() {
161161
assertEquals(0, cache.getStats().getInvalidationCount());
162162

163163
jedis.set("{csc}1", "new-one");
164+
Thread.sleep(1000);
164165
List<String> reply2 = jedis.mget("{csc}1", "{csc}2", "{csc}3");
165166
assertEquals(Arrays.asList("new-one", "two", "three"), reply2);
166167

0 commit comments

Comments
 (0)