@@ -430,10 +430,20 @@ public static void build(String cacheServerAddress, int minConcurrent, int maxCo |
430 | 430 | private CacheService service; |
431 | 431 |
|
432 | 432 | private L1Cache l1cache; |
433 | | - |
| 433 | + |
| 434 | + private static CacheClientMode clientMode; |
| 435 | + |
434 | 436 | protected CacheManager(String cacheServerAddress, int minConcurrent, int maxConcurrent, int queueSize, |
435 | 437 | String password) { |
436 | | - service = CacheFactory.instance().createCacheService(CacheClientMode.AREDIS, cacheServerAddress, minConcurrent, |
| 438 | + |
| 439 | + if (cacheServerAddress.contains(",")) { |
| 440 | + clientMode = CacheClientMode.LETTUCE; |
| 441 | + } |
| 442 | + else { |
| 443 | + clientMode = CacheClientMode.AREDIS; |
| 444 | + } |
| 445 | + |
| 446 | + service = CacheFactory.instance().createCacheService(clientMode, cacheServerAddress, minConcurrent, |
437 | 447 | maxConcurrent, queueSize, password); |
438 | 448 | l1cache = new L1Cache(); |
439 | 449 | } |
@@ -1239,7 +1249,8 @@ public void putHash(String region, String key, Map<String, String> fieldValues, |
1239 | 1249 | * @param fieldNames |
1240 | 1250 | * @return |
1241 | 1251 | */ |
1242 | | - public Map<String, String> getHash(String region, String key, String... fieldNames) { |
| 1252 | + @SuppressWarnings("unchecked") |
| 1253 | + public Map<String, String> getHash(String region, String key, String... fieldNames) { |
1243 | 1254 |
|
1244 | 1255 | if (null == fieldNames) { |
1245 | 1256 | Collections.emptyMap(); |
@@ -1253,8 +1264,13 @@ public Map<String, String> getHash(String region, String key, String... fieldNam |
1253 | 1264 |
|
1254 | 1265 | if (null != results && results.length > 0) { |
1255 | 1266 |
|
1256 | | - Map<String, String> value = genHMGetResults(fieldNames, results); |
1257 | | - |
| 1267 | + Map<String, String> value = new HashMap<String, String>(); |
| 1268 | + if (clientMode.equals(CacheClientMode.LETTUCE) && results[0] instanceof Map) { |
| 1269 | + value = (Map<String, String>) results[0]; |
| 1270 | + } |
| 1271 | + else { |
| 1272 | + value = genHMGetResults(fieldNames, results); |
| 1273 | + } |
1258 | 1274 | return value; |
1259 | 1275 | } |
1260 | 1276 |
|
@@ -1321,8 +1337,13 @@ public Map<String, String> getHashAll(String region, String key) { |
1321 | 1337 |
|
1322 | 1338 | if (null != results && results.length > 0) { |
1323 | 1339 |
|
1324 | | - Map<String, String> value = genHMGetResults(null, results); |
1325 | | - |
| 1340 | + Map<String, String> value = new HashMap<String, String>(); |
| 1341 | + if (clientMode.equals(CacheClientMode.LETTUCE) && results[0] instanceof Map) { |
| 1342 | + value = (Map<String, String>) results[0]; |
| 1343 | + } |
| 1344 | + else { |
| 1345 | + value = genHMGetResults(null, results); |
| 1346 | + } |
1326 | 1347 | this.l1cache.put(rkey, value); |
1327 | 1348 |
|
1328 | 1349 | return value; |
@@ -1362,7 +1383,14 @@ public void getHashAll(String region, String key, AsyncCacheCallback<Map<String, |
1362 | 1383 | public void process(CommandInfo[] command, Object[] result, Throwable throwable) { |
1363 | 1384 |
|
1364 | 1385 | if (fcallback != null && null != result && result.length > 0) { |
1365 | | - Map<String, String> mresult = genHMGetResults(null, result); |
| 1386 | + Map<String, String> mresult = new HashMap<String, String>(); |
| 1387 | + |
| 1388 | + if (clientMode.equals(CacheClientMode.LETTUCE) && result[0] instanceof Map) { |
| 1389 | + mresult = (Map<String, String>) result[0]; |
| 1390 | + } |
| 1391 | + else { |
| 1392 | + mresult = genHMGetResults(null, result); |
| 1393 | + } |
1366 | 1394 |
|
1367 | 1395 | /** |
1368 | 1396 | * get hash all是可以放L1Cache |
@@ -1403,12 +1431,18 @@ public void getHash(String region, String key, AsyncCacheCallback<Map<String, St |
1403 | 1431 |
|
1404 | 1432 | doCacheCommand(ci, new AbstractAsyncHandler<CommandInfo>() { |
1405 | 1433 |
|
1406 | | - @Override |
| 1434 | + @SuppressWarnings("unchecked") |
| 1435 | + @Override |
1407 | 1436 | public void process(CommandInfo[] command, Object[] result, Throwable throwable) { |
1408 | 1437 |
|
1409 | | - if (fcallback != null && null != result && result.length > 0) { |
1410 | | - Map<String, String> mresult = genHMGetResults(ffieldname, result); |
1411 | | - |
| 1438 | + if (fcallback != null && null != result && result.length > 0) { |
| 1439 | + Map<String, String> mresult = new HashMap<String, String>(); |
| 1440 | + if (clientMode.equals(CacheClientMode.LETTUCE) && result[0] instanceof Map) { |
| 1441 | + mresult = (Map<String, String>) result[0]; |
| 1442 | + } |
| 1443 | + else { |
| 1444 | + mresult = genHMGetResults(ffieldname, result); |
| 1445 | + } |
1412 | 1446 | fcallback.onResult(mresult); |
1413 | 1447 | } |
1414 | 1448 | } |
@@ -1795,7 +1829,7 @@ public List lrange(String region, String key, int start, int end) { |
1795 | 1829 | Object[] results = service.submitCommands( |
1796 | 1830 | new CommandInfo(CommandInfo.RedisCommand.LRANGE, rkey, String.valueOf(start), String.valueOf(end))); |
1797 | 1831 |
|
1798 | | - if (null != results && results.length > 0) { |
| 1832 | + if (null != results && results.length > 0 && results[0] != null) { |
1799 | 1833 |
|
1800 | 1834 | Object[] objs = (Object[]) results[0]; |
1801 | 1835 |
|
|