本文整理汇总了Java中redis.clients.jedis.Pipeline.expire方法的典型用法代码示例。如果您正苦于以下问题:Java Pipeline.expire方法的具体用法?Java Pipeline.expire怎么用?Java Pipeline.expire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Pipeline
的用法示例。
在下文中一共展示了Pipeline.expire方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pipelineWithTransaction
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public void pipelineWithTransaction() {
Jedis jedis = pool.getResource();
try {
Pipeline p = jedis.pipelined();
p.multi();
for (int i = 0; i < rowCount; i++) {
String key = RandomStringUtils.randomAlphabetic(8);
p.set(key, RandomStringUtils.randomNumeric(5));
p.expire(key, 5 * 60);
}
p.exec();
p.sync();
} catch (Exception e) {
pool.returnResource(jedis);
}
}
示例2: execute
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
String execute(Pipeline pipe) {
if (tokens.size() == 1) {
return tokenKey(tokens.get(0).text);
}
String[] keys = new String[tokens.size()+1];
keys[0] = makeTmpKey(raw);
for (int i = 0; i < tokens.size(); i++) {
keys[i+1] = tokenKey(tokens.get(i).text);
}
intersectTokens.execute(pipe, 1, keys);
pipe.expire(keys[0], DEFAULT_EXPIRATION);
return keys[0];
}
示例3: updateEvent
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public static boolean updateEvent(String prefix, int unixtime, final String[] events, boolean withSummary){
boolean commited = false;
try {
Date date = new Date(unixtime*1000L);
final String dateStr = DateTimeUtil.formatDate(date ,DateTimeUtil.DATE_FORMAT_PATTERN);
final String dateHourStr = DateTimeUtil.formatDate(date ,DateTimeUtil.DATE_HOUR_FORMAT_PATTERN);
RedisCommand<Boolean> cmd = new RedisCommand<Boolean>(jedisPool) {
@Override
protected Boolean build() throws JedisException {
String keyD = prefix+dateStr;
String keyH = prefix+dateHourStr;
Pipeline p = jedis.pipelined();
for (String event : events) {
if(withSummary){
p.hincrBy(SUMMARY, event , 1L);
}
//hourly
p.hincrBy(keyH, event , 1L);
p.expire(keyH, AFTER_15_DAYS);
//daily
p.hincrBy(keyD, event , 1L);
p.expire(keyD, AFTER_60_DAYS);
}
p.sync();
return true;
}
};
if(cmd != null) {
commited = cmd.execute();
}
} catch (Exception e) {
e.printStackTrace();
}
return commited;
}
示例4: pipelineWithoutTransaction
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public void pipelineWithoutTransaction() {
Jedis jedis = pool.getResource();
try {
Pipeline p = jedis.pipelined();
for (int i = 0; i < rowCount; i++) {
String key = RandomStringUtils.randomAlphabetic(8);
p.set(key, RandomStringUtils.randomNumeric(5));
p.expire(key, 5 * 60);
}
p.sync();
} catch (Exception e) {
pool.returnResource(jedis);
}
}
示例5: setAndExpireWithPipeline
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public void setAndExpireWithPipeline(){
Jedis jedis = getResource();
try {
Pipeline pipeline = jedis.pipelined();
pipeline.set("x", Long.valueOf(count.incrementAndGet()).toString());
pipeline.expire("x", 600);
pipeline.sync();
}finally {
returnResource(jedis);
}
}
示例6: pushValueInList
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
* Push an string into the Redis list and update the expire seconds.
* If the count of the list exceeds 'maxListCount', all the old content
* are trimmed.
*
* @param subject
* @param content
*/
public void pushValueInList(String list, String content, int maxListCount, int expireSeconds) {
Jedis jedisDB = JedisFactory.getJedisDB();
Pipeline pipeline = jedisDB.pipelined();
pipeline.lpush(list, content);
if ( maxListCount > 0 ) {
pipeline.ltrim(list, 0, maxListCount-1);
}
//update the expire seconds if exist
if ( expireSeconds > 0 ) {
pipeline.expire(list, expireSeconds);
}
pipeline.sync();
}
示例7: get
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public ValueType get(Object key) {
final String redisKey = generateRedisKey(turnObjectIntoKeyType(key));
final Response<String> valAsString;
try (final Handle handle = rdbi.open()) {
final Pipeline pl = handle.jedis().pipelined();
valAsString = pl.get(redisKey);
pl.expire(redisKey, valueTtl);
pl.sync();
}
return getFromResponse(valAsString);
}
示例8: setLastEntries
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void setLastEntries(Feed feed, List<String> entries) {
try (Jedis jedis = pool.getResource()) {
String key = buildRedisEntryKey(feed);
Pipeline pipe = jedis.pipelined();
pipe.del(key);
for (String entry : entries) {
pipe.sadd(key, entry);
}
pipe.expire(key, (int) TimeUnit.DAYS.toSeconds(7));
pipe.sync();
}
}
示例9: setUserRootCategory
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void setUserRootCategory(User user, Category category) {
try (Jedis jedis = pool.getResource()) {
String key = buildRedisUserRootCategoryKey(user);
Pipeline pipe = jedis.pipelined();
pipe.del(key);
pipe.set(key, MAPPER.writeValueAsString(category));
pipe.expire(key, (int) TimeUnit.MINUTES.toSeconds(30));
pipe.sync();
} catch (JsonProcessingException e) {
log.error(e.getMessage(), e);
}
}
示例10: setUnreadCount
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void setUnreadCount(FeedSubscription sub, UnreadCount count) {
try (Jedis jedis = pool.getResource()) {
String key = buildRedisUnreadCountKey(sub);
Pipeline pipe = jedis.pipelined();
pipe.del(key);
pipe.set(key, MAPPER.writeValueAsString(count));
pipe.expire(key, (int) TimeUnit.MINUTES.toSeconds(30));
pipe.sync();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
示例11: updateEventPageView
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public static boolean updateEventPageView(final String uuid, final String event, final String hostReferer, long delta){
boolean commited = false;
try {
Date date = new Date();
final String dateStr = DateTimeUtil.formatDate(date ,DateTimeUtil.DATE_FORMAT_PATTERN);
final String dateHourStr = DateTimeUtil.formatDate(date ,DateTimeUtil.DATE_HOUR_FORMAT_PATTERN);
RedisCommand<Boolean> cmd = new RedisCommand<Boolean>(jedisPool) {
@Override
protected Boolean build() throws JedisException {
Pipeline p = jedis.pipelined();
p.hincrBy(EVENT_STATS, event , delta);
p.pfadd(EVUT+event, uuid);
String keyH = PREFIX_PAGEVIEW+dateHourStr;
p.hincrBy(keyH, event , delta);
p.expire(keyH, AFTER_15_DAYS);
String keyD = PREFIX_PAGEVIEW+dateStr;
p.hincrBy(keyD, event , delta);
p.expire(keyD, AFTER_60_DAYS);
if(StringUtil.isNotEmpty(uuid)){
String keyHU = PREFIX_PAGEVIEW+dateHourStr + ":u";
p.pfadd(keyHU, uuid);
p.expire(keyHU, AFTER_3_DAYS);
String keyDU = PREFIX_PAGEVIEW+dateStr + ":u";
p.pfadd(keyDU, uuid);
p.expire(keyDU, AFTER_15_DAYS);
}
if(StringUtil.isNotEmpty(event)){
String keyHUT = PREFIX_PAGEVIEW+dateHourStr + ":u:"+event+":"+hostReferer;
p.pfadd(keyHUT, uuid);
p.expire(keyHUT, AFTER_3_DAYS);
String keyDUT = PREFIX_PAGEVIEW+dateStr + ":u:"+event+":"+hostReferer;
p.pfadd(keyDUT, uuid);
p.expire(keyDUT, AFTER_15_DAYS);
}
p.sync();
return true;
}
};
if(cmd != null) {
commited = cmd.execute();
}
} catch (Exception e) {
e.printStackTrace();
}
return commited;
}
示例12: updatePageViewEvent
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public static boolean updatePageViewEvent(final String host, final String uuid, final String tag){
boolean commited = false;
try {
Date date = new Date();
final String dateStr = DateTimeUtil.formatDate(date ,DateTimeUtil.DATE_FORMAT_PATTERN);
final String dateHourStr = DateTimeUtil.formatDate(date ,DateTimeUtil.DATE_HOUR_FORMAT_PATTERN);
RedisCommand<Boolean> cmd = new RedisCommand<Boolean>(jedisPool) {
@Override
protected Boolean build() throws JedisException {
Pipeline p = jedis.pipelined();
String keyH = PREFIX_PAGEVIEW+dateHourStr;
p.hincrBy(keyH, host , 1L);
p.expire(keyH, AFTER_15_DAYS);
String keyD = PREFIX_PAGEVIEW+dateStr;
p.hincrBy(keyD, host , 1L);
p.expire(keyD, AFTER_60_DAYS);
if(StringUtil.isNotEmpty(uuid)){
String keyHU = PREFIX_PAGEVIEW+dateHourStr + ":u";
p.pfadd(keyHU, uuid);
p.expire(keyHU, AFTER_3_DAYS);
String keyDU = PREFIX_PAGEVIEW+dateStr + ":u";
p.pfadd(keyDU, uuid);
p.expire(keyDU, AFTER_15_DAYS);
}
if(StringUtil.isNotEmpty(tag)){
String keyHUT = PREFIX_PAGEVIEW+dateHourStr + ":u:"+host+":"+tag;
p.pfadd(keyHUT, uuid);
p.expire(keyHUT, AFTER_3_DAYS);
String keyDUT = PREFIX_PAGEVIEW+dateStr + ":u:"+host+":"+tag;
p.pfadd(keyDUT, uuid);
p.expire(keyDUT, AFTER_15_DAYS);
}
p.sync();
return true;
}
};
if(cmd != null) {
commited = cmd.execute();
}
} catch (Exception e) {
e.printStackTrace();
}
return commited;
}
示例13: hashSet
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
private void hashSet(Jedis jedis, String cacheKey, String hfield, CacheWrapper<Object> result) throws Exception {
byte[] key=KEY_SERIALIZER.serialize(cacheKey);
byte[] field=KEY_SERIALIZER.serialize(hfield);
byte[] val=serializer.serialize(result);
int hExpire;
if(hashExpire < 0) {
hExpire=result.getExpire();
} else {
hExpire=hashExpire;
}
if(hExpire == 0) {
jedis.hset(key, field, val);
} else if(hExpire > 0) {
if(hashExpireByScript) {
String redisInstance = jedis.getClient().getHost()+":"+jedis.getClient().getPort();
byte[] sha=HASH_SET_SCRIPT_SHA.get(redisInstance);
if(null == sha) {
sha=jedis.scriptLoad(hashSetScript);
HASH_SET_SCRIPT_SHA.put(redisInstance, sha);
}
List<byte[]> keys=new ArrayList<byte[]>();
keys.add(key);
keys.add(field);
List<byte[]> args=new ArrayList<byte[]>();
args.add(val);
args.add(KEY_SERIALIZER.serialize(String.valueOf(hExpire)));
try {
jedis.evalsha(sha, keys, args);
} catch(Exception ex) {
logger.error(ex.getMessage(), ex);
try {
sha=jedis.scriptLoad(hashSetScript);
HASH_SET_SCRIPT_SHA.put(redisInstance, sha);
jedis.evalsha(sha, keys, args);
} catch(Exception ex1) {
logger.error(ex1.getMessage(), ex1);
}
}
} else {
Pipeline p=jedis.pipelined();
p.hset(key, field, val);
p.expire(key, hExpire);
p.sync();
}
}
}
示例14: save
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
* Simple session save to redis db.
*
* Depending on save settings, session manager will save the session every
* now and then.
*/
@Override
protected Object save(NoSqlSession session, Object version,
boolean activateAfterSave) {
final String sessionId = session.getId();
final String sessionMetadataId = sessionId + METADATA_SUFFIX;
final long newVersion = (version == null) ? 1 : ((Long) version + 1);
// If session has been invalidated then set the flags to indicate to
// other servers about the invalidation.
final String metadata = session.isValid() ? (newVersion + "," + session.getLastAccessedTime())
: "-1,-1";
final Map<String, Object> attrMap = session.isValid() ? ((RedisNoSqlSession) session).getAttributeMap()
: new HashMap<String, Object>();
Jedis jedis = null;
try {
// save the session
log.debug("saving for key: " + sessionId + " with version:"
+ newVersion);
jedis = jedisPool.getResource();
// Even in case of invalidate i.e. activateAfterSave=false, empty
// session will be saved.
Pipeline pipeline = jedis.pipelined();
byte[] value = serialize(attrMap);
pipeline.set(sessionId.getBytes(), value);
pipeline.set(sessionMetadataId, metadata);
// session will expire in 15 minutes if not touched. if it is
// accessed then its lifetime is further extended.
pipeline.expire(sessionId, SESSION_EXPIRY_TIME_SECONDS);
// this will execute all the commands at once.
pipeline.sync();
} catch (Exception e) {
//
log.error("couldn't save the session to redis db, "
+ "this will run into problems as session information "
+ "won't be available on other machines",
e);
return version;
} finally {
if (jedis != null) {
jedis.close();
}
}
// Activate the session after save, this triggers an event which is
// listened to by any configured listeners.
if (activateAfterSave) {
session.didActivate();
}
return newVersion;
}