io.vertx.redis.RedisClient.expire()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(375)

本文整理了Java中io.vertx.redis.RedisClient.expire方法的一些代码示例,展示了RedisClient.expire的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RedisClient.expire方法的具体详情如下:
包路径:io.vertx.redis.RedisClient
类名称:RedisClient
方法名:expire

RedisClient.expire介绍

[英]Set a key's time to live in seconds
[中]设置密钥的生存时间(以秒为单位)

代码示例

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Set a key's time to live in seconds
 * @param key Key string
 * @param seconds Time to live in seconds
 * @param handler Handler for the result of this call.
 * @return 
 */
public io.vertx.rxjava.redis.RedisClient expire(String key, long seconds, Handler<AsyncResult<Long>> handler) { 
 delegate.expire(key, seconds, handler);
 return this;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Set a key's time to live in seconds
 * @param key Key string
 * @param seconds Time to live in seconds
 * @param handler Handler for the result of this call.
 * @return 
 */
public io.vertx.rxjava.redis.RedisClient expire(String key, long seconds, Handler<AsyncResult<Long>> handler) { 
 delegate.expire(key, seconds, handler);
 return this;
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-queue

private static void handleStorage(RedisClient redisClient, final String redisKey, int ttl, final Handler<Boolean> callback) {
  // read from storage
  redisClient.get(redisKey, reply -> {
    if(reply.failed()){
      log.error("get command for redisKey '" + redisKey + "' resulted in cause " + logCause(reply));
      return;
    }
    if (!DEFAULT_REDIS_ENTRY_VALUE.equals(reply.result())) {
      // save to storage
      redisClient.setnx(redisKey, DEFAULT_REDIS_ENTRY_VALUE, setnxReply -> {
        if(setnxReply.failed()){
          log.error("set command for redisKey '" + redisKey + "' resulted in cause " + logCause(setnxReply));
          return;
        }
        // set expire
        redisClient.expire(redisKey, ttl, expireReply -> {
          if(expireReply.failed()){
            log.error("expire command for redisKey '" + redisKey + "' resulted in cause " + logCause(expireReply));
          }
        });
      });
      callback.handle(Boolean.FALSE);
    } else {
      log.info("received a duplicate request for redisKey: " + redisKey);
      callback.handle(Boolean.TRUE);
    }
  });
}

代码示例来源:origin: org.swisspush/gateleen-queue

private static void handleStorage(RedisClient redisClient, final String redisKey, int ttl, final Handler<Boolean> callback) {
  // read from storage
  redisClient.get(redisKey, reply -> {
    if(reply.failed()){
      log.error("get command for redisKey '" + redisKey + "' resulted in cause " + logCause(reply));
      return;
    }
    if (!DEFAULT_REDIS_ENTRY_VALUE.equals(reply.result())) {
      // save to storage
      redisClient.setnx(redisKey, DEFAULT_REDIS_ENTRY_VALUE, setnxReply -> {
        if(setnxReply.failed()){
          log.error("set command for redisKey '" + redisKey + "' resulted in cause " + logCause(setnxReply));
          return;
        }
        // set expire
        redisClient.expire(redisKey, ttl, expireReply -> {
          if(expireReply.failed()){
            log.error("expire command for redisKey '" + redisKey + "' resulted in cause " + logCause(expireReply));
          }
        });
      });
      callback.handle(Boolean.FALSE);
    } else {
      log.info("received a duplicate request for redisKey: " + redisKey);
      callback.handle(Boolean.TRUE);
    }
  });
}

代码示例来源:origin: org.swisspush/redisques

private void refreshRegistration(String queue, Handler<AsyncResult<Long>> handler) {
  log.debug("RedisQues Refreshing registration of queue " + queue + ", expire in " + consumerLockTime + " s");
  String key = getConsumersPrefix() + queue;
  if (log.isTraceEnabled()) {
    log.trace("RedisQues refresh registration: " + key);
  }
  redisClient.expire(key, consumerLockTime, handler);
}

相关文章

RedisClient类方法