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

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

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

Jedis.exists介绍

[英]Test if the specified key exists. The command returns true if the key exists, otherwise false is returned. Note that even keys set with an empty string as value will return true. Time complexity: O(1)
[中]测试指定的密钥是否存在。如果密钥存在,则命令返回true,否则返回false。请注意,即使将空字符串设置为值的键也将返回true。时间复杂度:O(1)

代码示例

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

@Override
public Boolean exists(byte[] key) {
  return jedis.exists(key);
}

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

@Override
public boolean exists(String key) {
  return jedis.exists(key);
}

代码示例来源:origin: sohutv/cachecloud

@Override
 public Long execute(Jedis connection) {
  return connection.exists(keys);
 }
}.runBinary(keys.length, keys);

代码示例来源:origin: sohutv/cachecloud

@Override
 public Boolean execute(Jedis connection) {
  return connection.exists(key);
 }
}.runBinary(key);

代码示例来源:origin: sohutv/cachecloud

@Override
 public Boolean execute(Jedis connection) {
  return connection.exists(key);
 }
}.run(key);

代码示例来源:origin: sohutv/cachecloud

@Override
 public Long execute(Jedis connection) {
  return connection.exists(keys);
 }
}.run(keys.length, keys);

代码示例来源:origin: sohutv/cachecloud

@Override
public Boolean exists(String key) {
 Jedis j = getShard(key);
 return j.exists(key);
}

代码示例来源:origin: sohutv/cachecloud

@Override
public Boolean exists(byte[] key) {
 Jedis j = getShard(key);
 return j.exists(key);
}

代码示例来源:origin: caoxinyu/RedisClient

@Override
protected void command() {
  jedis.select(db);
  exist = jedis.exists(key);
}

代码示例来源:origin: liyiorg/weixin-popular

@Override
public boolean exists(String key) {
  Jedis jedis = null;
  try {
    jedis = pool.getResource();
    return jedis.exists(perfix + key);
  } catch (Exception e) {
    logger.error("", e);
  } finally {
    if (jedis != null) {
      jedis.close();
    }
  }
  return false;
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

@Override
public Boolean exists(String key) {
  return (Boolean) this.excuteByJedis(j -> j.exists(key));
}

代码示例来源:origin: qiurunze123/miaosha

/**
 * 判断key是否存在
 * */
public <T> boolean exists(KeyPrefix prefix, String key) {
   Jedis jedis = null;
   try {
     jedis =  jedisPool.getResource();
    //生成真正的key
     String realKey  = prefix.getPrefix() + key;
    return  jedis.exists(realKey);
   }finally {
     returnToPool(jedis);
   }
}

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

@Override
public Boolean exists(String key) {
 Jedis jedis = null;
 try {
  jedis = jedisPool.getResource();
  return jedis.exists(key);
 } finally {
  if (jedis != null)
   jedis.close();
 }
}

代码示例来源:origin: jfinal/jfinal

/**
 * 检查给定 key 是否存在。
 */
public boolean exists(Object key) {
  Jedis jedis = getJedis();
  try {
    return jedis.exists(keyToBytes(key));
  }
  finally {close(jedis);}
}

代码示例来源:origin: caoxinyu/RedisClient

@Override
protected void command() {
  jedis.select(db);
  if(jedis.exists(key) && getValueType(key) != NodeType.HASH)
    throw new RuntimeException(RedisClient.i18nFile.getText(I18nFile.HASHEXIST)+ key);
  jedis.hmset(key, values);
}

代码示例来源:origin: caoxinyu/RedisClient

@Override
protected void command() {
  jedis.select(db);
  if(jedis.exists(key) && getValueType(key) != NodeType.SORTEDSET)
    throw new RuntimeException(RedisClient.i18nFile.getText(I18nFile.ZSETEXIST)+key);
  addZSet();
    
  
}

代码示例来源:origin: caoxinyu/RedisClient

@Override
protected void command() {
  jedis.select(db);
  if(jedis.exists(key) && getValueType(key) != NodeType.SET)
    throw new RuntimeException(RedisClient.i18nFile.getText(I18nFile.SETEXIST)+key);
  addSet();
}

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

private void testExpire(Expiration exp) throws Exception {
  try (Jedis jedis = pool.getResource()) {
    jedis.set("k1", "v1");
    Assert.assertTrue(jedis.exists("k1"));
    Assert.assertEquals(1L, exp.expire(jedis, "k1"));
    Assert.assertEquals("v1", jedis.get("k1"));
    Thread.sleep(2100);
    Assert.assertFalse(jedis.exists("k1"));
    Assert.assertEquals(0L, (long)jedis.expire("k1", 2));
  }
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testExists() throws Exception {
  jcache().put("existsKey1", "abc");
  jcache().put("existsKey2", "abcd");
  try (Jedis jedis = pool.getResource()) {
    Assert.assertFalse(jedis.exists("nonExistingDelKey"));
    Assert.assertEquals(2, (long)jedis.exists("existsKey1", "existsKey2"));
  }
}

代码示例来源:origin: caoxinyu/RedisClient

@Override
protected void command() {
  jedis.select(db);
  if (jedis.exists(key) && getValueType(key) != NodeType.LIST)
    throw new RuntimeException(RedisClient.i18nFile.getText(I18nFile.LISTEXIST) + key);
  beforeAdd();
  
  for (String value : values) {
    if (headTail && exist)
      jedis.rpush(key, value);
    else if (headTail && !exist)
      jedis.rpushx(key, value);
    else if (!headTail && exist)
      jedis.lpush(key, value);
    else
      jedis.lpushx(key, value);
  }
  afterAdd();
}

相关文章

Jedis类方法