使用Jedis连接Redis并操作HyperLogLog
import redis.clients.jedis.Jedis;public class RedisHyperLogLogExample {public static void main(String[] args) {// 连接到本地的Redis服务Jedis jedis = new Jedis("localhost", 6379);String hyperLogLogKey = "hll_example";// 添加元素到HyperLogLogjedis.pfadd(hyperLogLogKey, "element1");jedis.pfadd(hyperLogLogKey, "element2");jedis.pfadd(hyperLogLogKey, "element3");jedis.pfadd(hyperLogLogKey, "element1"); // 重复的元素// 获取HyperLogLog的基数估计值long estimatedCardinality = jedis.pfcount(hyperLogLogKey);System.out.println("Estimated cardinality: " + estimatedCardinality);// 清理数据jedis.del(hyperLogLogKey);// 关闭Jedis连接jedis.close();}
}