當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis類代碼示例

本文整理匯總了Java中redis.clients.jedis.Jedis的典型用法代碼示例。如果您正苦於以下問題:Java Jedis類的具體用法?Java Jedis怎麽用?Java Jedis使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Jedis類屬於redis.clients.jedis包,在下文中一共展示了Jedis類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: listObjectAdd

import redis.clients.jedis.Jedis; //導入依賴的package包/類
/**
 * 向List緩存中添加值
 * @param key 鍵
 * @param value 值
 * @return
 */
public static long listObjectAdd(String key, Object... value) {
	long result = 0;
	Jedis jedis = null;
	try {
		jedis = getResource();
		List<byte[]> list = Lists.newArrayList();
		for (Object o : value){
			list.add(toBytes(o));
		}
		result = jedis.rpush(getBytesKey(key), (byte[][])list.toArray());
		logger.debug("listObjectAdd {} = {}", key, value);
	} catch (Exception e) {
		logger.warn("listObjectAdd {} = {}", key, value, e);
	} finally {
		returnResource(jedis);
	}
	return result;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:25,代碼來源:JedisUtils.java

示例2: zScore

import redis.clients.jedis.Jedis; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
public Double zScore(String key, Object data) {
	int tries = 0;
	boolean sucess = false;
	Double retVal = null;
	do {
		tries++;
		try {
			Jedis jedis = pool.getResource();
			retVal = jedis.zscore(key, SerializationUtil.serialize(data));
			jedis.close();
			sucess = true;
		} catch (JedisConnectionException ex) {
			log.error(RedisConstants.CONN_FAILED_RETRY_MSG + tries);
			if (tries == numRetries) {
				throw ex;
			}
		}
	} while (!sucess && tries <= numRetries);
	return retVal;
}
 
開發者ID:ran-jit,項目名稱:distributed-task-scheduler,代碼行數:23,代碼來源:RedisDataCache.java

示例3: hgetAllObjects

import redis.clients.jedis.Jedis; //導入依賴的package包/類
@Override
public <T> Map<String, T> hgetAllObjects(final String bizkey, final String nameSpace, final TypeReference<T> type,
        final GetDataCallBack<T> gbs) {
    final String key = CacheUtils.getKeyByNamespace(bizkey, nameSpace);
    return this.performFunction(key, new CallBack<Map<String, T>>() {
        public Map<String, T> invoke(Jedis jedis) {
            try {
                Map<String, String> all = jedis.hgetAll(key);
                Map<String, T> allObjs = new HashMap<String, T>();
                for (Entry<String, String> item : all.entrySet()) {
                    String _key = item.getKey();
                    T _value = CacheUtils.parseObject(key, item.getValue(), type);
                    allObjs.put(_key, _value);
                }
                return allObjs;
            } catch (Exception e) {
                logger.error("key:" + key + "hgetAllObjects Exception:" + e.getMessage());
            }
            return null;
        }
    });
}
 
開發者ID:ningyu1,項目名稱:redis-client,代碼行數:23,代碼來源:RedisClientImpl.java

示例4: getLenBySet

import redis.clients.jedis.Jedis; //導入依賴的package包/類
/**
 * 獲取Set長度
 * @param setKey
 * @return
 */
public Long getLenBySet(String setKey) throws Exception {
	Jedis jds = null;
	try {
		jds = getJedis();
		jds.select(0);
		Long result = jds.scard(setKey);
		return result;
	} catch (Exception e) {
		throw e;
	} finally {
		if(jds != null)
		{
			jds.close();
		}
	}
}
 
開發者ID:wjggwm,項目名稱:webside,代碼行數:22,代碼來源:RedisManager.java

示例5: expireat

import redis.clients.jedis.Jedis; //導入依賴的package包/類
@Override
public boolean expireat(String key, String val, int cacheTime) {
	Jedis jedis = getJedisPool().getResource();
	try {
		jedis.set(key, val);
		if (cacheTime > 0) {
			jedis.expire(key, cacheTime);
		}
		return true;
	} catch (Exception e) {
		logger.error("expireat ", e);
		return false;
	} finally {
		getJedisPool().returnResource(jedis);
	}
}
 
開發者ID:zh-cn-trio,項目名稱:trioAop,代碼行數:17,代碼來源:RedisStringOperationImpl.java

示例6: 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;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:RedisService.java

示例7: getActiveSessions

import redis.clients.jedis.Jedis; //導入依賴的package包/類
/**
 * 獲取會話列表
 * @param offset
 * @param limit
 * @return
 */
public Map getActiveSessions(int offset, int limit) {
    Map sessions = new HashMap();
    Jedis jedis = RedisUtil.getJedis();
    // 獲取在線會話總數
    long total = jedis.llen(ZHENG_UPMS_SERVER_SESSION_IDS);
    // 獲取當前頁會話詳情
    List<String> ids = jedis.lrange(ZHENG_UPMS_SERVER_SESSION_IDS, offset, (offset + limit - 1));
    List<Session> rows = new ArrayList<>();
    for (String id : ids) {
        String session = RedisUtil.get(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + id);
        // 過濾redis過期session
        if (null == session) {
            RedisUtil.lrem(ZHENG_UPMS_SERVER_SESSION_IDS, 1, id);
            total = total - 1;
            continue;
        }
         rows.add(SerializableUtil.deserialize(session));
    }
    jedis.close();
    sessions.put("total", total);
    sessions.put("rows", rows);
    return sessions;
}
 
開發者ID:ChangyiHuang,項目名稱:shuzheng,代碼行數:30,代碼來源:UpmsSessionDao.java

示例8: pushWhenNoRepeat

import redis.clients.jedis.Jedis; //導入依賴的package包/類
@Override
protected void pushWhenNoRepeat(Task task, Request request) {
    Jedis jedis = jedisPool.getResource();
    try {
        String content = serializer.serialize(request);
        if(request.getPriority() == 0) {
            jedis.rpush(RedisKeys.getQueueNoPriorityKey(task), content);
        } else if (request.getPriority() > 0) {
            jedis.zadd(RedisKeys.getZsetPlusPriorityKey(task), request.getPriority(), content);
        } else {
            jedis.zadd(RedisKeys.getZsetMinusPriorityKey(task), request.getPriority(), content);
        }

        jedis.sadd(RedisKeys.getSetKey(task), request.key());
    } finally {
        jedis.close();
    }
}
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:19,代碼來源:RedisPriorityScheduler.java

示例9: publish

import redis.clients.jedis.Jedis; //導入依賴的package包/類
private static void publish(int id, String string)
{
    Jedis jedis = null;
    try
    {
        jedis = SamaGamesAPI.get().getBungeeResource();
        if (jedis != null)
            jedis.publish("tsbot", SamaGamesAPI.get().getServerName() + "/" + id + ":" + string);
    }
    catch (Exception exception)
    {
        SamaGamesAPI.get().getPlugin().getLogger().log(Level.SEVERE, "Jedis error", exception);
    }
    finally
    {
        if (jedis != null)
            jedis.close();
    }
}
 
開發者ID:SamaGames,項目名稱:SamaGamesAPI,代碼行數:20,代碼來源:TeamSpeakAPI.java

示例10: zrem

import redis.clients.jedis.Jedis; //導入依賴的package包/類
public void zrem(String key, String member) {
    Jedis jedis = null;
    try {
        jedis = getJedis();
        if (jedis == null) {
            logger.error("get jedis fail");
        }
        jedis.zrem(key, member);
    } catch (JedisConnectionException e) {
        if (jedis != null) {
            jedis.close();
        }
    } finally {
        returnJedisResource(jedis);
    }
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:17,代碼來源:JedisUtil.java

示例11: lpop

import redis.clients.jedis.Jedis; //導入依賴的package包/類
public String lpop(String key) {
	Jedis jedis = null;
	boolean success = true;
	String ret = null;
	try {
		jedis = jedisPool.getResource();
		if (jedis == null) {
			success = false;
			return ret;
		}
		ret = jedis.lpop(key);
	} catch (Exception e) {
		success = false;
		returnBrokenResource(jedis, "lpop key:" + key, e);
	} finally {
		releaseReidsSource(success, jedis);
	}
	return ret;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:RedisService.java

示例12: ttl

import redis.clients.jedis.Jedis; //導入依賴的package包/類
public Long ttl(String key) {
    log.trace("get set expire " + key);
    Jedis jedis = null;
    try {
        jedis = redisConnection.getJedis();
        jedis.select(dbIndex);
        return jedis.ttl(key);
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
    return -2L;
}
 
開發者ID:gaochao2000,項目名稱:redis_util,代碼行數:17,代碼來源:CacheServiceRedisImpl.java

示例13: hget

import redis.clients.jedis.Jedis; //導入依賴的package包/類
/**
 * If key holds a hash, retrieve the value associated to the specified field.
 * <p>
 * If the field is not found or the key does not exist, a special 'nil' value is returned.
 * <p>
 * <b>Time complexity:</b> O(1)
 * 
 * @param key specified key
 * @param field hash field
 * @return Bulk reply
 */
@Override
public String hget(final String bizkey,final String nameSpace, final String field,final GetDataCallBack<String> gbs) {
	final String key = CacheUtils.getKeyByNamespace(bizkey,nameSpace);
	return this.performFunction(key, new CallBack<String>() {
        public String invoke(Jedis jedis) {
            String res = jedis.hget(key, field);
        	if(StringUtils.isEmpty(res)){
        		if(null!=gbs){
        			res = gbs.invoke();
        			if(StringUtils.isNotEmpty(res)){
        				hset(bizkey,nameSpace,field,res);
        			}
        		}
        	}
            return res;
        }
    });
}
 
開發者ID:ningyu1,項目名稱:jodis-client,代碼行數:30,代碼來源:RedisClientImpl.java

示例14: createIndex

import redis.clients.jedis.Jedis; //導入依賴的package包/類
/**
 * Create the index definition in redis
 * @param schema a schema definition, see {@link Schema}
 * @param options index option flags, see {@link IndexOptions}
 * @return true if successful
 */
public boolean createIndex(Schema schema, IndexOptions options) {
    Jedis conn = _conn();

    ArrayList<String> args = new ArrayList<>();

    args.add(indexName);

    options.serializeRedisArgs(args);

    args.add("SCHEMA");

    for (Schema.Field f : schema.fields) {
        f.serializeRedisArgs(args);
    }

    String rep = conn.getClient()
            .sendCommand(commands.getCreateCommand(),
                         args.toArray(new String[args.size()]))
            .getStatusCodeReply();
    conn.close();
    return rep.equals("OK");

}
 
開發者ID:RedisLabs,項目名稱:JRediSearch,代碼行數:30,代碼來源:Client.java

示例15: hlen

import redis.clients.jedis.Jedis; //導入依賴的package包/類
@Override
public Long hlen(String key) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = pool.getResource();
        res = jedis.hlen(key);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;

}
 
開發者ID:wxiaoqi,項目名稱:ace-cache,代碼行數:17,代碼來源:RedisServiceImpl.java


注:本文中的redis.clients.jedis.Jedis類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。