redis.clients.jedis.JedisCommands.set()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(148)

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

JedisCommands.set介绍

暂无

代码示例

代码示例来源:origin: Netflix/conductor

public String set(String key, String value) {
  String retVal = dynoClient.set(key, value);
  return retVal;
}

代码示例来源:origin: com.github.bingoohuang/westid

@SneakyThrows
private Integer tryReuseWorkerId() {
  val pidWorkerIds = jedis.lrange(PREFIX_PID, 0, -1);
  if (pidWorkerIds.size() == 0) {
    return null;
  }
  boolean locked = jedis.setnx(PREFIX_LOK, Os.PID_STRING) == 1;
  if (!locked) {
    return null;
  }
  @Cleanup val i = new Closeable() {
    @Override
    public void close() throws IOException {
      jedis.del(PREFIX_LOK);
    }
  };
  val workerId = findUsableWorkerId(pidWorkerIds);
  if (workerId == null) {
    return null;
  }
  jedis.set(PREFIX_USE + workerId, Os.PID_STRING + "x" + Os.IP_STRING + "x" + Os.HOSTNAME);
  return Integer.parseInt(workerId);
}

代码示例来源:origin: mpusher/mpush

/**
 * @param key
 * @param value
 * @param time  seconds
 */
public void set(String key, String value, int time) {
  call(jedis -> {
    jedis.set(key, value);
    if (time > 0) {
      jedis.expire(key, time);
    }
  });
}

代码示例来源:origin: apache/storm

jedisCommand.set(key, value);
break;

代码示例来源:origin: com.netflix.conductor/conductor-redis-persistence

public String set(String key, String value) {
  String retVal = dynoClient.set(key, value);
  return retVal;
}

代码示例来源:origin: com.netflix.spinnaker.orca/orca-redis

@Override
 public boolean tryAcquireLock(@Nonnull String notificationType, long lockTimeoutSeconds) {
  String key = "lock:" + notificationType;
  return redisClientDelegate.withCommandsClient(client -> {
   return "OK".equals(client.set(key, "\uD83D\uDD12", "NX", "EX", lockTimeoutSeconds));
  });
 }
}

代码示例来源:origin: com.netflix.spinnaker.echo/echo-pubsub-core

private Boolean acquireMessageLock(String messageKey, String identifier, Integer ackDeadlineSeconds) {
 String response = redisClientDelegate.withCommandsClient(c -> {
  return c.set(messageKey, identifier, SET_IF_NOT_EXIST, SET_EXPIRE_TIME_SECONDS, ackDeadlineSeconds);
 });
 return SUCCESS.equals(response);
}

代码示例来源:origin: liuht777/Taroco

private boolean setRedis(final String key, final long expire) {
  try {
    String result = redisTemplate.execute((RedisCallback<String>) connection -> {
      JedisCommands commands = (JedisCommands) connection.getNativeConnection();
      String uuid = UUID.randomUUID().toString();
      lockFlag.set(uuid);
      return commands.set(key, uuid, "NX", "PX", expire);
    });
    return !StringUtils.isEmpty(result);
  } catch (Exception e) {
    log.error("set redisDistributeLock occured an exception", e);
  }
  return false;
}

代码示例来源:origin: com.y3tu/y3tu-tool-web

private boolean setRedis(final String key, final long expire) {
  try {
    String result = redisTemplate.execute((RedisCallback<String>) connection -> {
      JedisCommands commands = (JedisCommands) connection.getNativeConnection();
      String uuid = UUID.randomUUID().toString();
      lockFlag.set(uuid);
      return commands.set(key, uuid, "NX", "PX", expire);
    });
    return !StringUtils.isEmpty(result);
  } catch (Exception e) {
    log.error("set redisDistributeLock occured an exception", e);
  }
  return false;
}

代码示例来源:origin: com.github.mpusher/mpush-cache

/**
 * @param key
 * @param value
 * @param time  seconds
 */
public void set(String key, String value, int time) {
  call(jedis -> {
    jedis.set(key, value);
    if (time > 0) {
      jedis.expire(key, time);
    }
  });
}

代码示例来源:origin: com.y3tu/y3tu-tool-web

/**
 * 重写redisTemplate的set方法
 * <p>
 * 命令 SET resource-name anystring NX EX max-lock-time 是一种在 Redis 中实现锁的简单方法。
 * <p>
 * 客户端执行以上的命令:
 * <p>
 * 如果服务器返回 OK ,那么这个客户端获得锁。
 * 如果服务器返回 NIL ,那么客户端获取锁失败,可以在稍后再重试。
 *
 * @param key     锁的Key
 * @param value   锁里面的值
 * @param seconds 过去时间(秒)
 * @return String
 */
private String set(final String key, final String value, final long seconds) {
  Assert.isTrue(!StringUtils.isEmpty(key), "key不能为空");
  return redisTemplate.execute((RedisConnection connection) -> {
    Object nativeConnection = connection.getNativeConnection();
    String result = null;
    if (nativeConnection instanceof JedisCommands) {
      result = ((JedisCommands) nativeConnection).set(key, value, NX, EX, seconds);
    }
    if (!StringUtils.isEmpty(lockKeyLog) && !StringUtils.isEmpty(result)) {
      log.debug("获取锁{}的时间:{}", lockKeyLog, System.currentTimeMillis());
    }
    return result;
  });
}

代码示例来源:origin: aillamsun/devX

private boolean putLockKey(long leaseMillSec) {
  RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection();
  JedisCommands commands = (JedisCommands) redisConnection.getNativeConnection();
  String res = commands.set(key, getCurrThreadId(), "NX", "PX", leaseMillSec);
  redisConnection.close();
  return (res != null && "OK".equalsIgnoreCase(res)) || redisTemplate.opsForValue().get(key).equals(getCurrThreadId());
}

代码示例来源:origin: gudaoxuri/dew

private boolean putLockKey(long leaseMillSec) {
  RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection();
  String res = ((JedisCommands) redisConnection.getNativeConnection()).set(key, getCurrThreadId(), "NX", "PX", leaseMillSec);
  redisConnection.close();
  return "OK".equalsIgnoreCase(res);
}

代码示例来源:origin: com.gitee.qdbp/qdbp-general-biz

/** {@inheritDoc} **/
@Override
public void set(String key, String subkey, Object value, Long expire) {
  JedisCommands jedis = this.getInstanceByKey(key);
  jedis.set(concat(key, subkey), serializeValue(value));
  if (expire != null) {
    expire(key, subkey, expire);
  }
}

代码示例来源:origin: com.gitee.zhaohuihua/bdp-general-svc

/** {@inheritDoc} **/
@Override
protected void set(String key, String subkey, Object value, Long expire) {
  JedisCommands jedis = this.getInstanceByKey(key);
  jedis.set(concat(key, subkey), serializeValue(value));
  if (expire != null) {
    expire(concat(key, subkey), expire);
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * 检查给定 key 是否存在。
 * @return
 */
public boolean set(String value, Date expireAt) {
  if (value == null)
    return false;
  try {
    boolean result = getJedisCommands(groupName).set(key, value).equals(RESP_OK);
    if(result){
      result = setExpireAt(expireAt);
      //set可能是更新缓存,所以统一通知各节点清除本地缓存
      Level1CacheSupport.getInstance().publishSyncEvent(key);
    }
    return result;
  } finally {
    getJedisProvider(groupName).release();
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * 设置缓存指定过期时间间隔
 * @param value
 * @param seconds (过期秒数 ,小于等于0时 不设置)
 * @return
 */
public boolean set(String value, long seconds) {
  if (value == null)
    return false;
  try {
    boolean result = getJedisCommands(groupName).set(key, value).equals(RESP_OK);
    if(result && seconds > 0){
      result =  setExpire(seconds);
      //set可能是更新缓存,所以统一通知各节点清除本地缓存
      Level1CacheSupport.getInstance().publishSyncEvent(key);
    }
    return result;
  } finally {
    getJedisProvider(groupName).release();
  }
  
}

代码示例来源:origin: com.netflix.spinnaker.orca/orca-redis

c.set(
 format("correlation:%s", execution.getTrigger().getCorrelationId()),
 execution.getId()

相关文章

微信公众号

最新文章

更多