php技术

redis插件安装-bloom模块

2020-03-16  本文已影响0人  北海北_6dc3

布隆过滤器

Redis 官方提供的布隆过滤器到了 Redis 4.0 提供了插件功能之后才正式登场。布隆过滤
器作为一个插件加载到 Redis Server 中,给 Redis 提供了强大的布隆去重功能

特性

当布隆过滤器说某个值存在时,这个值可能不存在;当它说不存在时,那就肯定不存

如何安装

下载并编译

[root]# wget "https://github.com/RedisBloom/RedisBloom/archive/v2.2.0.tar.gz"
[root]# tar zxvf v2.2.0.tar.gz 
[root]# cd  RedisBloom-2.2.0/
[root]# make
[root]# ll
-rwxr-xr-x 1 root root 331600 Mar 16 20:15 redisbloom.so

加载

./redis-server  ./../redis.conf   --loadmodule /opt/cache/RedisBloom-2.2.0/redisbloom.so

使用

<! --默认值,格式为  bf.reserve key  error_rate  initial_size-->
127.0.0.1:6379> bf.reserve email 0.01 100
OK
127.0.0.1:6379> bf.add emai liyi@163.com
(integer) 1
127.0.0.1:6379> bf.add emai liyi2@163.com
(integer) 1
<! ---重复添加,返回值0-->
127.0.0.1:6379> bf.add emai liyi2@163.com
(integer) 0
<! ---不存在,一定不存在-->
127.0.0.1:6379> bf.exists emai liyi@163.com1
(integer) 0
<! ---存在,可能不存在-->
127.0.0.1:6379> bf.exists emai liyi@163.com
(integer) 1
上一篇下一篇

猜你喜欢

热点阅读