首页 > 代码库 > redis集群(jedis)批量删除同一前缀

redis集群(jedis)批量删除同一前缀

public Set<String> getByPrefix(String key) {
        Set<String> setResult = new HashSet<>();
        try {
            ShardedJedis jedis  = redisDataSource.getJedisClient();
            Iterator<Jedis> jedisIterator = jedis.getAllShards().iterator();
            while(jedisIterator.hasNext()){
                setResult = jedisIterator.next().keys(key+"*");
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return setResult;
    }

 

redis集群(jedis)批量删除同一前缀