文章目录
1、查看redis是否启动
[root@localhost ~]# ps -ef | grep redis
root 4270 1 0 05:51 ? 00:00:47 /usr/local/redis/bin/redis-server *:6379
root 10173 6858 0 14:37 pts/0 00:00:00 grep --color=auto redis
[root@localhost ~]#
2、通过客户端连接redis
[root@localhost ~]# /usr/local/redis/bin/redis-cli -p 6379
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
3、切换到db6数据库
127.0.0.1:6379> select 6
OK
127.0.0.1:6379[6]>
4、将元素添加到HyperLogLog数据结构中
Probabilistic Filter 即概率过滤器,它是一种数据结构,用于估计一个集合中不同元素的数量,而不需要存储每个元素,只需要存储一些元素的哈希值。在 Redis 中,概率过滤器以 pf 开头的命令来使用,例如 pfadd、pfcount 等。
127.0.0.1:6379[6]> pfadd list01 a b c d e b d e x
(integer) 1
127.0.0.1:6379[6]>
5、估算存储在给定键中的集合的基数(即集合中不同元素的数量)
127.0.0.1:6379[6]> pfcount list01
(integer) 6
127.0.0.1:6379[6]>
127.0.0.1:6379[6]> pfadd list01 a b c d e b d e x
(integer) 1
127.0.0.1:6379[6]> pfcount list01
(integer) 6
127.0.0.1:6379[6]> pfadd list02 o p q x y z
(integer) 1
127.0.0.1:6379[6]> pfcount list02
(integer) 6
127.0.0.1:6379[6]> pfcount list01 list02
(integer) 11
127.0.0.1:6379[6]>
6、将多个HyperLogLog合并为一个HyperLogLog
127.0.0.1:6379[6]> pfmerge list03 list01 list02
OK
127.0.0.1:6379[6]> pfcount list03
(integer) 11
127.0.0.1:6379[6]>