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


Java ShardedJedis.expire方法代碼示例

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


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

示例1: set

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
/**
 * 設置單個值
 *
 * @param key   鍵
 * @param value 值
 * @return 結果
 */
public String set(String key, String value, int timeout) {
    String result = null;
    ShardedJedis shardedJedis = shardedJedisPool.getResource();

    if (shardedJedis == null) {
        return null;
    }
    try {
        result = shardedJedis.set(key, value);
        if (0 != timeout) {
            shardedJedis.expire(key, timeout);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        shardedJedis.close();
    }
    return result;
}
 
開發者ID:peng9627,項目名稱:hall,代碼行數:27,代碼來源:RedisClientTemplate.java

示例2: expire

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
/**
 * 在某段時間後實現
 *
 * @param key     鍵
 * @param seconds 時間
 * @return 返回
 */
public Long expire(String key, int seconds) {
    Long result = null;
    ShardedJedis shardedJedis = shardedJedisPool.getResource();
    if (shardedJedis == null) {
        return null;
    }
    try {
        result = shardedJedis.expire(key, seconds);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        shardedJedis.close();
    }
    return result;
}
 
開發者ID:peng9627,項目名稱:hall,代碼行數:23,代碼來源:RedisClientTemplate.java

示例3: lock

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
/**
 * 獲取分布式鎖
 *
 * @param lockedKey 建議業務名稱+業務主鍵
 * @param timeout   獲取分布式鎖的超時時間(毫秒)
 * @return true:獲取鎖成功,fasle:獲取鎖失敗
 */
public boolean lock(String lockedKey, long timeout) {
    long nano = System.nanoTime();
    ShardedJedis shardedJedis = shardedJedisPool.getResource();
    long timeoutNanos = timeout * 1000000L;
    while ((System.nanoTime() - nano) < timeoutNanos) {
        if (shardedJedis.setnx(lockedKey, CoreDateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS")) == 1) {
            shardedJedis.expire(lockedKey, 5);
            log.info("RedisSimpleLockUtils.lock-->lockedKey=‘{}’ , timeout={}毫秒", lockedKey, timeout);
            return true;
        }
        // 短暫休眠,nano避免出現活鎖
        try {
            Thread.sleep(2, new Random().nextInt(500));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
開發者ID:peng9627,項目名稱:hall,代碼行數:27,代碼來源:RedisClientTemplate.java

示例4: run

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
public <K> K run(String key, Executor<K> executor, Integer... expire) {
	ShardedJedis jedis = getJedis();
	if (jedis == null) {
		return null;
	}
	try {
		K result = executor.execute(jedis);
		if (jedis.exists(key)) {
			if (expire == null || expire.length == 0) {
				jedis.expire(key, EXPIRE);
			} else if (expire.length == 1) {
				jedis.expire(key, expire[0]);
			}
		}
		return result;
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	} finally {
		if (jedis != null) {
			jedis.close();
		}
	}
	return null;
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:25,代碼來源:JedisTemplate.java

示例5: run

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
public static <K> K run(String key, Executor<K> executor, Integer... expire) {
    ShardedJedis jedis = getJedis();
    if (jedis == null) {
        return null;
    }
    try {
        K result = executor.execute(jedis);
        if (jedis.exists(key)) {
            if (expire == null || expire.length == 0) {
                jedis.expire(key, EXPIRE);
            } else if (expire.length == 1) {
                jedis.expire(key, expire[0]);
            }
        }
        return result;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
    return null;
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:25,代碼來源:JedisTemplate.java

示例6: increment

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Override
public long increment(final String key, final int expire, final Callback<Long> callback) {
	checkParameters(key, callback);
	final ShardedJedis jedis = getJedis();

	long incr = jedis.incr(key);
	jedis.expire(key, expire);

	try {
		incr = callback.callback(incr);
	} catch (final Exception e) {
		throw new IncrementRedisException("method: increment, key: " + key + ", incr: " + incr, e);
	}

	returnResource(jedis);
	return incr;
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:18,代碼來源:RedisServiceImpl.java

示例7: expire

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
/**
 * 給對應key設置存活時間
 */
@Override
public long expire(String key, int seconds) {
	ShardedJedis redis = null;
	long r = 0L;
	try {
		redis = pool.getResource();
		key = getKeyAll(key);
		r = redis.expire(key, seconds);
		return r;
	} catch (RuntimeException e) { 
        if(redis != null ) {
	        pool.returnBrokenResource(redis);
	    }
        logger.error("redis expire(String key, int seconds):", e);
        return r;
	} finally{ 
         if(redis != null ) {
            pool.returnResource(redis);
         }
	}
	
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:26,代碼來源:RedisCacheClient.java

示例8: set

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Override
public boolean set(final String key, final String value, final int expire) {
	checkParameters(key, value);
	final ShardedJedis jedis = getJedis();
	final String result = jedis.set(key, value);
	jedis.expire(key, expire);
	returnResource(jedis);
	return SUCCESS.equalsIgnoreCase(result);
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:10,代碼來源:RedisServiceImpl.java

示例9: saveMap

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Override
public boolean saveMap(final String key, final Map<String, String> value, final int expire) {
	checkParameters(key, value);

	final ShardedJedis jedis = getJedis();
	final String result = jedis.hmset(key, value);
	jedis.expire(key, expire);

	returnResource(jedis);
	return SUCCESS.equalsIgnoreCase(result);
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:12,代碼來源:RedisServiceImpl.java

示例10: hset

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Override
public boolean hset(final String key, final String field, final String value, final int expire) {
	checkParameters(key, field, value);

	final ShardedJedis jedis = getJedis();
	final long result = jedis.hset(key, field, value);

	jedis.expire(key, expire);

	returnResource(jedis);
	return result == 0;
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:13,代碼來源:RedisServiceImpl.java

示例11: hmset

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Override
public boolean hmset(final String key, final Map<String, String> hash, final int expire) {
	checkParameters(key, hash);

	final ShardedJedis jedis = getJedis();
	try {
		final String result = jedis.hmset(key, hash);
		jedis.expire(key, expire);
		return SUCCESS.equalsIgnoreCase(result);
	} catch (final JedisConnectionException e) {
		throw new MapRedisException("method: hmset, key:" + key, e);
	} finally {
		returnResource(jedis);
	}
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:16,代碼來源:RedisServiceImpl.java


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