本文整理匯總了Java中redis.clients.jedis.Jedis.select方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.select方法的具體用法?Java Jedis.select怎麽用?Java Jedis.select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.select方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: lock
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public String lock(String key) {
Jedis jedis = null;
try {
jedis = redisConnection.getJedis();
jedis.select(dbIndex);
key = KEY_PRE + key;
String value = fetchLockValue();
if (SET_SUCCESS.equals(jedis.set(key, value, "NX", "EX", lockExpirseTime))) {
log.debug("Reids Lock key : " + key + ",value : " + value);
return value;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jedis != null) {
jedis.close();
}
}
return null;
}
示例2: expire
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public boolean expire(String key, int expireSecond) {
log.trace("strar set expire " + key);
Jedis jedis = null;
try {
jedis = redisConnection.getJedis();
jedis.select(dbIndex);
return jedis.expire(key, expireSecond) == 1;
} catch (Exception e) {
log.warn(e.getMessage(), e);
} finally {
if (jedis != null) {
jedis.close();
}
}
return false;
}
示例3: clear
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public void clear() throws CacheException {
Jedis jedis = null;
try
{
jedis = redisManager.getJedis();
jedis.select(DB_INDEX);
jedis.flushDB();
}finally
{
if(null != jedis)
{
jedis.close();
}
}
}
示例4: delByMapKey
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 刪除Map裏的值
* @param mapKey
* @param dkey
* @return
*/
public Object delByMapKey(String mapKey ,String...dkey) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
byte[][] dx = new byte[dkey.length][];
for (int i = 0; i < dkey.length; i++) {
dx[i] = dkey[i].getBytes();
}
Long result = jds.hdel(mapKey.getBytes(), dx);
return result;
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例5: fetchDailyUUID
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public Long fetchDailyUUID(String key, Integer length, Boolean haveDay) {
Jedis jedis = null;
try {
jedis = redisConnection.getJedis();
jedis.select(dbIndex);
Calendar now = new GregorianCalendar();
String day = df.format(now.getTime());
key = key + "_" + day;
Long num = jedis.incr(key);
//設置 key 過期時間
if (num == 1) {
jedis.expire(key, (24 - now.get(Calendar.HOUR_OF_DAY)) * 3600 + 1800);
}
if (haveDay) {
return createUUID(num, day, length);
} else {
return num;
}
} finally {
if (jedis != null) {
jedis.close();
}
}
}
示例6: fetchUUID
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public Long fetchUUID(String key, Integer length, Boolean haveDay) {
Jedis jedis = null;
try {
jedis = redisConnection.getJedis();
jedis.select(dbIndex);
Calendar now = new GregorianCalendar();
Long num = jedis.incr(key);
if (haveDay) {
String day = df.format(now.getTime());
return createUUID(num, day, length);
} else {
return num;
}
} finally {
if (jedis != null) {
jedis.close();
}
}
}
示例7: getValueByKey
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public byte[] getValueByKey(int dbIndex, byte[] key) throws Exception {
Jedis jedis = null;
byte[] result = null;
try {
jedis = getJedis();
jedis.select(dbIndex);
result = jedis.get(key);
} catch (Exception e) {
throw e;
} finally {
if(null != jedis)
{
jedis.close();
}
}
return result;
}
示例8: getVByList
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 往redis裏取set整個集合
*
* @param <T>
* @param setKey
* @param start
* @param end
* @param requiredType
* @return
*/
@SuppressWarnings("unchecked")
public <T> Set<T> getVByList(String setKey,Class<T> requiredType) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
Set<T> set = new TreeSet<T>();
Set<byte[]> xx = jds.smembers(setKey.getBytes());
for (byte[] bs : xx) {
T t = SerializeUtil.deserialize(bs, requiredType);
set.add(t);
}
return set;
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例9: 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;
}
示例10: setVBySet
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 往redis裏存Set
* @param setKey
* @param value
*/
public void setVBySet(String setKey,String value) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
jds.sadd(setKey, value);
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例11: exists
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 判斷是否存在
* @param existskey
* @return
*/
public boolean exists(String existskey) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
return jds.exists(existskey.getBytes());
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例12: setVByMap
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
*
* @param mapkey map
* @param key map裏的key
* @param value map裏的value
*/
public void setVByMap(String mapkey,String key ,Object value) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
byte[] svalue = SerializeUtil.serialize(value);
jds.hset(mapkey.getBytes(), key.getBytes(),svalue);
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例13: setex
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 過期時間的
* @param key
* @param value
* @param timer (秒)
*/
public void setex(String key, Object value, int timer) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
byte[] svalue = SerializeUtil.serialize(value);
jds.setex(key.getBytes(), timer, svalue);
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例14: available
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public boolean available(){
Jedis jedis = getJedis();
if(jedis!=null){
jedis.select(0);
String key = "[email protected]";
jedis.set(key,"available");
if("available".equals(jedis.get(key))){
jedis.del(key);
return true;
}
}else{
return false;
}
return false;
}
示例15: acquireConnection
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
protected Jedis acquireConnection() {
Jedis jedis = connectionPool.getResource();
if (getDatabase() != 0) {
jedis.select(getDatabase());
}
return jedis;
}