Skip to content

Commit

Permalink
update JedisClusterWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Jan 5, 2022
1 parent baefb32 commit 4fa2e83
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import redis.clients.util.JedisClusterCRC16;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Set;
import java.util.*;

/**
*
Expand All @@ -16,19 +15,27 @@
public class JedisClusterWrapper extends JedisCluster {

private JedisClusterInfoCache cache;
private Field slots;

private void init() {
try {
Field cacheField = JedisClusterConnectionHandler.class.getDeclaredField("cache");
cacheField.setAccessible(true);
cache = (JedisClusterInfoCache)cacheField.get(this.connectionHandler);
slots = JedisClusterInfoCache.class.getDeclaredField("slots");
slots.setAccessible(true);
} catch (Exception e) {
throw new CamelliaRedisException(e);
}
}

public List<JedisPool> getJedisPoolList() {
return cache.getShuffledNodesPool();
try {
Map<Integer, JedisPool> map = (Map<Integer, JedisPool>) slots.get(this.cache);
return new ArrayList<>(new HashSet<>(map.values()));
} catch (Exception e) {
throw new CamelliaRedisException(e);
}
}

public JedisPool getJedisPool(String key) {
Expand Down

0 comments on commit 4fa2e83

Please sign in to comment.