华为大数据平台FusionInsight HD Redis批量删除key方法

spark程序突然跑不起来,排查后发现原来是内存满了。(可以通过redis客户端的 info memory命令查看)

./redis-cli -h 127.0.0.1 -p 6379
info memory

网上查到的批量方案

./redis-cli -h 127.0.0.1 -p 6379 keys "mykeys*" | xargs ./redis-cli -h 127.0.0.1 -p 6379 del

运行后报错。好像在华为的FusionInsight HD集群这种方案行不通。

后来通过阅读源码,在ClusterUtil的类发现可以批量删除key的方法。

  public void batchDelete(String pattern, int tryTimes)
  {
    if (tryTimes <= 0) {
      throw new IllegalArgumentException("tryTimes must be greater than or equal to 0");
    }
    ScanParams scanRarams = new ScanParams().match(pattern).count(1000);
    Set<JedisPool> pools = this.jedisCluster.getServingNodes();
    CountDownLatch latch = new CountDownLatch(pools.size() * tryTimes);
    try
    {
      for (int i = 0; i < tryTimes; i++) {
        for (JedisPool jedisPool : pools) {
          this.threadPool.submit(new DelRunnable(jedisPool, scanRarams, latch));
        }
      }
      latch.await();
    }
    catch (InterruptedException e)
    {
      throw new JedisException(e);
    }
  }

关注公众号“大模型全栈程序员”回复“小程序”获取1000个小程序打包源码。更多免费资源在http://www.gitweixin.com/?p=2627

发表评论

邮箱地址不会被公开。 必填项已用*标注