本文整理匯總了Java中redis.clients.jedis.Jedis.hget方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.hget方法的具體用法?Java Jedis.hget怎麽用?Java Jedis.hget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.hget方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getHgetString
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 必須強製獲取成功狀態
*
* @param key
* @param field
* @return
*/
public String getHgetString(String key, String field) throws Exception {
Jedis jedis = null;
boolean success = true;
String ret = null;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.hget(key, field);
} catch (Exception e) {
success = false;
releaseBrokenReidsSource(jedis, key, "getHString", e, false);
// throw e;
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例2: hget
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public String hget(String key, String field) {
Jedis jedis = null;
boolean success = true;
String ret = null;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.hget(key, field);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "hmgetString" + key, e);
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例3: recoverConfig
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 重刷配置.
* @param name 應用opkind
* @throws Exception Exception
*/
public void recoverConfig(final String name) throws Exception{
Jedis monitorJedis = monitorJedisPool.getResource();
Jedis configJedis = o2iJedisPool.getResource();
String configStr = monitorJedis.hget(REDIS_CONFIG, name);
O2iConfig o2iConfig = JSON.parseObject(configStr, O2iConfig.class);
for(int i = 0; i< o2iConfig.getThreadNum(); i++){
RedisConfig rc = new RedisConfig();
rc.setDataRange(String.valueOf(i));
rc.setDataSource(o2iConfig.getDataSource());
rc.setJobSwitch("on");
rc.setJobType(o2iConfig.getJobType());
rc.setThreadType(o2iConfig.getThreadType());
configJedis.set(o2iConfig.getJobType()+"-"+o2iConfig.getThreadType()+"-"+o2iConfig.getDataSource()+"-"+i, JSON.toJSONString(rc));
}
monitorJedis.close();
configJedis.close();
}
示例4: configModify
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 調整默認的配置數量.
* @param name 應用opkind
* @param num 數量
* @return ResultMap
*/
public ResultMap configModify(final String name, final int num){
ResultMap resultMap = null;
Jedis monitorJedis = monitorJedisPool.getResource();
try {
String value = monitorJedis.hget(REDIS_CONFIG, name);
O2iConfig o2iConfig = JSON.parseObject(value, O2iConfig.class);
o2iConfig.setThreadNum(num);
monitorJedis.hset(REDIS_CONFIG, name, JSON.toJSONString(o2iConfig));
resultMap = ResultMap.create("修改配置成功", HttpStatus.OK);
} catch (final Exception e) {
resultMap = ResultMap.create(HttpStatus.INTERNAL_SERVER_ERROR.value(), "修改配置失敗", e.getMessage());
}
monitorJedis.close();
return resultMap;
}
示例5: poll
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public synchronized Request poll(String spiderName) {
Jedis jedis = pool.getResource();
try {
String url = jedis.lpop(getQueueKey(spiderName));
if (url == null) {
return null;
}
String key = ITEM_PREFIX + url;
String field = DigestUtils.shaHex(url);
byte[] bytes = jedis.hget(key.getBytes(), field.getBytes());
if (bytes != null) {
Request o = JSON.parseObject(new String(bytes), Request.class);
return o;
}
Request request = new Request(url);
return request;
} finally {
pool.returnResource(jedis);
}
}
示例6: poll
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public synchronized Request poll(ISpider spider) {
Jedis jedis = pool.getResource();
try {
String url = jedis.lpop(getQueueKey(spider));
if (url == null) {
return null;
}
String key = ITEM_PREFIX + spider.getName();
String field = DigestUtils.md5Hex(url);
byte[] bytes = jedis.hget(key.getBytes(), field.getBytes());
Request request=SerializationUtils.deserialize(bytes);
return request;
} finally {
jedis.close();
}
}
示例7: get
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public ResourceItem get(String queueID, String key) {
if (!lockQueue(queueID)) {
return null;
}
@Cleanup Jedis jedis = jedisPool.getResource();
try {
String dataJson = jedis.hget(makeDataKey(queueID), key);
if (isNil(dataJson)) {
return null;
}
return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
} finally {
unLockQueue(queueID);
}
}
示例8: lookup
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public <T> T lookup(Mcf mcf, Class<T> cls) {
String key = mcf.buildRoot(super.nurl).getPrefixKey();
String field = mcf.getSuffixKey();
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
String json = jedis.hget(key, field);
return (T) json2Obj(json, cls);
} catch (Exception e) {
logger.error("The pull conf exception.", e);
return null;
} finally {
if (jedis != null) {
jedis.close();
}
}
}
示例9: poll
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public ResourceItem poll(String queueID) {
if (!lockQueue(queueID)) {
return null;
}
Jedis jedis = jedisPool.getResource();
try {
String firstResourceKey = jedis.lpop(makePoolQueueKey(queueID));
if (isNil(firstResourceKey)) {
return null;
}
String dataJson = jedis.hget(makeDataKey(queueID), firstResourceKey);
if (isNil(dataJson)) {
throw new IllegalStateException("this is no meta data for key queue :" + queueID + " ,for resourceKey :" + firstResourceKey);
}
jedis.hdel(makeDataKey(queueID), firstResourceKey);
return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
} finally {
IOUtils.closeQuietly(jedis);
unLockQueue(queueID);
}
}
示例10: get
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public ResourceItem get(String queueID, String key) {
if (!lockQueue(queueID)) {
return null;
}
Jedis jedis = jedisPool.getResource();
try {
String dataJson = jedis.hget(makeDataKey(queueID), key);
if (isNil(dataJson)) {
return null;
}
return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
} finally {
IOUtils.closeQuietly(jedis);
unLockQueue(queueID);
}
}
示例11: hget
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public String hget(String hkey, String key) {
String value = null;
Jedis jedis = jedisPool.getResource();
try {
value = jedis.hget(hkey, key);
} catch (Exception e) {
jedisPool.returnBrokenResource(jedis);
} finally {
jedisPool.returnResource(jedis);
}
return value;
}
示例12: getObjectFromList
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 從緩存裏還原一個列表對象
*
* @param key
* @param clazz
* @return
*/
@SuppressWarnings("unchecked")
public <T> T getObjectFromList(String key, String subUnionkey, Class<?> clazz, int seconds) {
Jedis jedis = null;
boolean success = true;
RedisListInterface po = null;
Map<String, String> mapFields = null;
try {
if (clazz == null) {
success = false;
return null;
}
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return null;
}
String value = jedis.hget(key, subUnionkey);
if (!StringUtils.isEmpty(value)) {
mapFields = JSON.parseObject(value.replaceAll("=", ":"), HashMap.class);
po = (RedisListInterface) clazz.newInstance();
if (po != null) {
ObjectUtils.getObjFromMap(mapFields, po);
}
if (seconds >= 0) {
jedis.expire(key, seconds);
}
}
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "getObjectFromList:" + key, e);
} finally {
releaseReidsSource(success, jedis);
}
return (T) po;
}
示例13: getCache
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public String getCache(String key, String field) {
Jedis jedis = null;
String var4;
try {
jedis = pool.getResource();
var4 = jedis.hget(key, field);
} catch (Exception var8) {
throw new RuntimeException(var8);
} finally {
pool.returnResourceObject(jedis);
}
return var4;
}
示例14: hget
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public String hget(String key, String field) {
Jedis jedis = jedisPool.getResource();
String result = jedis.hget(key, field);
jedis.close();
return result;
}
示例15: hget
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public String hget(String mapName, String key) {
String value = null;
Jedis jedis = null;
try {
jedis = get();
if (jedis == null)
return "";
value = jedis.hget(mapName, key);
pool.returnResource(jedis);
} catch (Exception e) {
pool.returnBrokenResource(jedis);
}
return value;
}