Skip to content

Commit

Permalink
Merge pull request #463 from wanglinlin8/master
Browse files Browse the repository at this point in the history
Redis supports cluster configuration
  • Loading branch information
zengli00 authored Dec 21, 2018
2 parents a442483 + 48ec4e8 commit 812a291
Show file tree
Hide file tree
Showing 4 changed files with 735 additions and 16 deletions.
38 changes: 37 additions & 1 deletion com.creditease.uav.cache.redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.11.Final</version>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>5.0.5.RELEASE</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-resolver</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,20 @@ public static void build(String cacheServerAddress, int minConcurrent, int maxCo
private CacheService service;

private L1Cache l1cache;


private static CacheClientMode clientMode;

protected CacheManager(String cacheServerAddress, int minConcurrent, int maxConcurrent, int queueSize,
String password) {
service = CacheFactory.instance().createCacheService(CacheClientMode.AREDIS, cacheServerAddress, minConcurrent,

if (cacheServerAddress.contains(",")) {
clientMode = CacheClientMode.LETTUCE;
}
else {
clientMode = CacheClientMode.AREDIS;
}

service = CacheFactory.instance().createCacheService(clientMode, cacheServerAddress, minConcurrent,
maxConcurrent, queueSize, password);
l1cache = new L1Cache();
}
Expand Down Expand Up @@ -1239,7 +1249,8 @@ public void putHash(String region, String key, Map<String, String> fieldValues,
* @param fieldNames
* @return
*/
public Map<String, String> getHash(String region, String key, String... fieldNames) {
@SuppressWarnings("unchecked")
public Map<String, String> getHash(String region, String key, String... fieldNames) {

if (null == fieldNames) {
Collections.emptyMap();
Expand All @@ -1253,8 +1264,13 @@ public Map<String, String> getHash(String region, String key, String... fieldNam

if (null != results && results.length > 0) {

Map<String, String> value = genHMGetResults(fieldNames, results);

Map<String, String> value = new HashMap<String, String>();
if (clientMode.equals(CacheClientMode.LETTUCE) && results[0] instanceof Map) {
value = (Map<String, String>) results[0];
}
else {
value = genHMGetResults(fieldNames, results);
}
return value;
}

Expand Down Expand Up @@ -1321,8 +1337,13 @@ public Map<String, String> getHashAll(String region, String key) {

if (null != results && results.length > 0) {

Map<String, String> value = genHMGetResults(null, results);

Map<String, String> value = new HashMap<String, String>();
if (clientMode.equals(CacheClientMode.LETTUCE) && results[0] instanceof Map) {
value = (Map<String, String>) results[0];
}
else {
value = genHMGetResults(null, results);
}
this.l1cache.put(rkey, value);

return value;
Expand Down Expand Up @@ -1362,7 +1383,14 @@ public void getHashAll(String region, String key, AsyncCacheCallback<Map<String,
public void process(CommandInfo[] command, Object[] result, Throwable throwable) {

if (fcallback != null && null != result && result.length > 0) {
Map<String, String> mresult = genHMGetResults(null, result);
Map<String, String> mresult = new HashMap<String, String>();

if (clientMode.equals(CacheClientMode.LETTUCE) && result[0] instanceof Map) {
mresult = (Map<String, String>) result[0];
}
else {
mresult = genHMGetResults(null, result);
}

/**
* get hash all是可以放L1Cache
Expand Down Expand Up @@ -1403,12 +1431,18 @@ public void getHash(String region, String key, AsyncCacheCallback<Map<String, St

doCacheCommand(ci, new AbstractAsyncHandler<CommandInfo>() {

@Override
@SuppressWarnings("unchecked")
@Override
public void process(CommandInfo[] command, Object[] result, Throwable throwable) {

if (fcallback != null && null != result && result.length > 0) {
Map<String, String> mresult = genHMGetResults(ffieldname, result);

if (fcallback != null && null != result && result.length > 0) {
Map<String, String> mresult = new HashMap<String, String>();
if (clientMode.equals(CacheClientMode.LETTUCE) && result[0] instanceof Map) {
mresult = (Map<String, String>) result[0];
}
else {
mresult = genHMGetResults(ffieldname, result);
}
fcallback.onResult(mresult);
}
}
Expand Down Expand Up @@ -1795,7 +1829,7 @@ public List lrange(String region, String key, int start, int end) {
Object[] results = service.submitCommands(
new CommandInfo(CommandInfo.RedisCommand.LRANGE, rkey, String.valueOf(start), String.valueOf(end)));

if (null != results && results.length > 0) {
if (null != results && results.length > 0 && results[0] != null) {

Object[] objs = (Object[]) results[0];

Expand Down
Loading

0 comments on commit 812a291

Please sign in to comment.