本文整理匯總了Java中redis.clients.jedis.ShardedJedis.hgetAll方法的典型用法代碼示例。如果您正苦於以下問題:Java ShardedJedis.hgetAll方法的具體用法?Java ShardedJedis.hgetAll怎麽用?Java ShardedJedis.hgetAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.ShardedJedis
的用法示例。
在下文中一共展示了ShardedJedis.hgetAll方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hgetAll
import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
/**
* 通過hash key獲取所有對象
* @param key
* @param clazz
* @param <T>
* @return
*/
public <T> Map<String, T> hgetAll(String key, Class<T> clazz) {
ShardedJedis redis = null;
Map<String, T> map = new HashMap<>();
try {
redis = pool.getResource();
key = getKeyAll(key);
Map<String, String> result = redis.hgetAll(key);
if (!Check.NuNMap(result)) {
for (String mapKey : result.keySet()) {
map.put(mapKey, JsonEntityTransform.json2Object(result.get(mapKey), clazz));
}
}
return map;
} catch (RuntimeException e) {
if(redis != null ) {
pool.returnBrokenResource(redis);
}
logger.error("redis hegeAll(String key):", e);
return map;
} finally{
if(redis != null ) {
pool.returnResource(redis);
}
}
}
示例2: updateStayTime
import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
public void updateStayTime() {
ShardedJedis jedis = JedisPoolManager.getResource();
Map<String, String> map = jedis.hgetAll(TableConstants.TABLE_USER);
if(map.size() > 0) {
List<Object> userBeanList = new ArrayList<>();
for (Map.Entry<String, String> user : map.entrySet()) {
UserBean userBean = JSON.parseObject(user.getValue(), UserBean.class);
String firstVisitTime = jedis.lindex(user.getKey(), 0);
userBean.setFirst_time(DateUtil.stampToDate(firstVisitTime));
Long len = jedis.llen(user.getKey());
String LastVisitTime = "";
Long stayTime = 0L;
if (len > 1) {
LastVisitTime = jedis.lindex(user.getKey(), len - 1);
stayTime = Long.valueOf(LastVisitTime) - Long.valueOf(firstVisitTime) + 3;
userBean.setRecent_time(DateUtil.stampToDate(LastVisitTime));
} else {
stayTime = 3000L;
userBean.setRecent_time("-");
}
Long visitCycle = 0L;
userBean.setStayTime(stayTime);
userBean.setVisitCycle(visitCycle);
userBeanList.add(userBean);
}
System.out.println("insert ....");
this.add(userBeanList);
}
System.out.println("nothing insert ....");
jedis.close();
}
示例3: hgetAll
import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Override
public <T> T hgetAll(final String key, final Callback<T> callback) {
checkParameters(key, callback);
final ShardedJedis jedis = getJedis();
final Map<String, String> result = jedis.hgetAll(key);
try {
return callback.callback(result);
} catch (final Exception e) {
throw new GetValueRedisException("method: hgetAll, key: " + key + ", result: " + result, e);
} finally {
returnResource(jedis);
}
}