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

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

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

Jedis.randomKey介绍

[英]Return a randomly selected key from the currently selected DB.

Time complexity: O(1)
[中]从当前选定的数据库返回随机选择的密钥。
时间复杂度:O(1)

代码示例

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

/**
 * 从当前数据库中随机返回(不删除)一个 key 。
 */
public String randomKey() {
  Jedis jedis = getJedis();
  try {
    return jedis.randomKey();
  }
  finally {close(jedis);}
}

代码示例来源:origin: io.leopard/leopard-redis

@Override
public String randomKey() {
  return jedis.randomKey();
}

代码示例来源:origin: io.leopard/leopard-redis

@Override
  public Object execute(Jedis jedis) {
    return jedis.randomKey();
  }
});

代码示例来源:origin: mindwind/craft-atom

private String randomkey0(Jedis j) {
  return j.randomKey();
}

代码示例来源:origin: io.leopard/leopard-redis

@Override
public String randomKey() {
  return jedis.randomKey();
}

代码示例来源:origin: penggle/jedis-ms-sentinel

public String randomKey() {
  return master.randomKey();
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public String randomKey() {
 String command = "randomKey";
 return instrumented(command, () -> delegated.randomKey());
}

代码示例来源:origin: io.enoa/nosql-redis

default String randomkey() {
 return this.run((jedis, serializer) -> jedis.randomKey());
}

代码示例来源:origin: yangfuhai/jboot

/**
 * 从当前数据库中随机返回(不删除)一个 key 。
 */
public String randomKey() {
  Jedis jedis = getJedis();
  try {
    return jedis.randomKey();
  } finally {
    returnResource(jedis);
  }
}

代码示例来源:origin: com.github.sogyf/goja-jfinal

/**
 * 从当前数据库中随机返回(不删除)一个 key 。
 */
public String randomKey() {
  Jedis jedis = getJedis();
  try {
    return jedis.randomKey();
  }
  finally {close(jedis);}
}

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

/**
 * 从当前数据库中随机返回(不删除)一个 key 。
 */
public String randomKey() {
  Jedis jedis = getJedis();
  try {
    return jedis.randomKey();
  }
  finally {close(jedis);}
}

代码示例来源:origin: org.nutz/nutz-integration-jedis

/**
 * Return a randomly selected key from the currently selected DB.
 * <p>
 * Time complexity: O(1)
 *
 * @return Singe line reply, specifically the randomly selected key or an empty string is the
 * database is empty
 */
public String randomKey() {
  Jedis jedis = getJedis();
  try {
    return jedis.randomKey();
  } finally {Streams.safeClose(jedis);}
}

代码示例来源:origin: biezhi/java-library-examples

public static void main(String[] args) {
  try (Jedis jedis = JedisUtil.getInstance().getJedis()) {
    // select db-index
    System.out.println(jedis.select(0));
    // 通过索引选择数据库,默认连接的数据库所有是0,默认数据库数是16个。返回1表示成功,0失败
    // dbsize 返回当前数据库的key数量
    System.out.println(jedis.dbSize());
    // 返回匹配指定模式的所有key
    System.out.println(jedis.keys("*"));
    System.out.println(jedis.randomKey());
    // 删除当前数据库中所有key,此方法不会失败。慎用
    jedis.flushDB();
    // 删除所有数据库中的所有key,此方法不会失败。更加慎用
    jedis.flushAll();
  }
}

代码示例来源:origin: youtongluan/sumk

@Override
public java.lang.String randomKey() {
  Exception e1 = null;
  for (int i = 0; i < tryCount; i++) {
    Jedis jedis = null;
    try {
      jedis = pool.getResource();
      return jedis.randomKey();
    } catch (Exception e) {
      if (isConnectException(e)) {
        Log.get(LOG_NAME).error(this.hosts + " - redis connection failed,idle=" + pool.getNumIdle()
            + ",active=" + pool.getNumActive(), e);
        e1 = e;
        continue;
      }
      Log.get(LOG_NAME).error("randomKey - redis execute error!" + e.getMessage(), e);
      SumkException.throwException(12342411, e.getMessage(), e);
    } finally {
      close(jedis);
    }
  }
  handleRedisException(e1);
  throw new SumkException(12342423, "未知redis异常");
}

相关文章

微信公众号

最新文章

更多

Jedis类方法