redis-lua-scaling-bloom-filter
==============================
`add.lua`, `cas.lua` and `check.lua` are three lua scripts for a [scaling bloom filter](http://en.wikipedia.org/wiki/Bloom_filter#Scalable_Bloom_filters) for [Redis](http://redis.io/)
`layer-add.lua` and `later-check.lua` are two lua scripts for a [scaling layered bloom filter](https://en.wikipedia.org/wiki/Bloom_filter#Layered_Bloom_filters) for [Redis](http://redis.io/)
The scripts are to be executed using the [EVAL](http://redis.io/commands/eval) command in Redis.
_These scripts will probably not work on Redis cluster since the keys used inside the script aren't all passed as arguments!_
The layered filter has a maximum number of 32 layers. You can modify this in the source.
`add.lua`, `cas.lua` and `layer-add.lua`
----------------------------------------
The `add.lua` script adds a new element to the filter. It will create the filter when it doesn't exist yet.
`cas.lua` does a Check And Set, this will not add the element if it already exist.
`cas.lua` will return 0 if the element is added, or 1 if the element was already in the filter.
Since we use a scaling filter adding an element using `add.lua` might cause the element
to exist in multiple parts of the filter at the same time. `cas.lua` prevents this.
Using only `cas.lua` the `:count` key of the filter will accurately count the number of elements added to the filter.
Only using `cas.lua` will also lower the number of false positives by a small amount (less duplicates in the filter means less bits set).
`layer-add.lua` does a similar thing to `cas.lua` since this is necessary for the layer part to work
(need to check all the filters in a layer to see if it already exists in the layer).
`layer-add.lua` will return the layer number the element was added to.
These scripts expects 4 arguments.
1. The base name of the keys to use.
2. The initial size of the bloom filter (in number of elements).
3. The probability of false positives.
4. The element to add to the filter.
For example the following call would add "something" to a filter named test
which will initially be able to hold 10000 elements with a probability of false positives of 1%.
`
eval "add.lua source here" 0 test 10000 0.01 something
`
`check.lua` and `layer-check.lua`
---------------------------------
The `check.lua` and `layer-check.lua` scripts check if an element is contained in the bloom filter.
`layer-check.lua` returns the layer the element was found in.
These scripts expects 4 arguments.
1. The base name of the keys to use.
2. The initial size of the bloom filter (in number of elements).
3. The probability of false positives.
4. The element to check for.
For example the following call would check if "something" is part of the filter named test
which will initially be able to hold 10000 elements with a probability of false positives of 1%.
`
eval "check.lua source here" 0 test 10000 0.01 something
`
Tests
-----
```
$ npm install redis srand
$ node add.js
$ node cas.js
$ node check.js
$ # or/and
$ node layer-add.js
$ node layer-check.js
```
`add.js` and `layer-add.js` will add elements to a filter named test and then check if the elements are part of the filter.
`check.js` and `layer-check.js` will test random elements against the filter build by `add.js` or `layer-add.js` to find the probability of false positives.
Both script assume Redis is running on the default port.
Benchmark
---------
You can run `./benchmark.sh` and `./layer-benchmark.sh` to see how fast the scripts are.
This script assumes Redis is running on the default port and `redis-cli` and `redis-benchmark` are installed.
This is the outputs on my 2.3GHz 2012 MacBook Pro Retina:
```
add.lua
====== evalsha ab31647b3931a68b3b93a7354a297ed273349d39 0 HSwVBmHECt 1000000 0.01 :rand:000000000000 ======
200000 requests completed in 8.27 seconds
20 parallel clients
3 bytes payload
keep alive: 1
94.57% <= 1 milliseconds
100.00% <= 2 milliseconds
24175.03 requests per second
check.lua
====== evalsha 437a3b0c6a452b5f7a1f10487974c002d41f4a04 0 HSwVBmHECt 1000000 0.01 :rand:000000000000 ======
200000 requests completed in 8.54 seconds
20 parallel clients
3 bytes payload
keep alive: 1
92.52% <= 1 milliseconds
100.00% <= 8 milliseconds
23419.20 requests per second
layer-add.lua
====== evalsha 7ae29948e3096dd064c22fcd8b628a5c77394b0c 0 ooPb5enskU 1000000 0.01 :rand:000000000000 ======
20000 requests completed in 12.61 seconds
20 parallel clients
3 bytes payload
keep alive: 1
55.53% <= 12 milliseconds
75.42% <= 13 milliseconds
83.71% <= 14 milliseconds
91.48% <= 15 milliseconds
97.76% <= 16 milliseconds
99.90% <= 24 milliseconds
100.00% <= 24 milliseconds
1586.04 requests per second
layer-check.lua
====== evalsha c1386438944daedfc4b5c06f79eadb6a83d4b4ea 0 ooPb5enskU 1000000 0.01 :rand:000000000000 ======
20000 requests completed in 11.13 seconds
20 parallel clients
3 bytes payload
keep alive: 1
0.00% <= 9 milliseconds
74.12% <= 11 milliseconds
80.43% <= 12 milliseconds
83.93% <= 13 milliseconds
97.43% <= 14 milliseconds
99.89% <= 15 milliseconds
100.00% <= 15 milliseconds
1797.59 requests per second
```
没有合适的资源?快使用搜索试试~ 我知道了~
用于扩展布隆过滤器 的 LUA Redis 脚本_JavaScript_代码_相关文件_下载
共16个文件
js:5个
lua:5个
sh:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 116 浏览量
2022-07-12
22:01:03
上传
评论
收藏 16KB ZIP 举报
温馨提示
add.lua,cas.lua并且是用于Redis的缩放布隆过滤器check.lua的三个 lua 脚本 layer-add.lua并且是用于Redis的缩放分层布隆过滤器later-check.lua的两个 lua 脚本 这些脚本将使用Redis中的EVAL命令执行。 这些脚本可能无法在 Redis 集群上运行,因为脚本中使用的键并非全部作为参数传递! 分层过滤器的最大层数为 32 层。您可以在源代码中修改它。 add.lua,cas.lua和layer-add.lua 该add.lua脚本将一个新元素添加到过滤器。当过滤器尚不存在时,它将创建过滤器。 cas.lua执行检查并设置,如果元素已经存在,则不会添加该元素。 cas.lua如果添加了元素,则返回 0,如果元素已经在过滤器中,则返回 1。由于我们使用缩放过滤器,因此添加元素add.lua可能会导致该元素同时存在于过滤器的多个部分中。cas.lua防止这种情况。仅使用过滤器cas.lua的:count键将准确计算添加到过滤器的元素数量。 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
redis-lua-scaling-bloom-filter-master.zip (16个子文件)
redis-lua-scaling-bloom-filter
layer-benchmark.sh 981B
cas.lua 3KB
check.lua 2KB
cas.js 2KB
layer-check.lua 2KB
layer-add.js 3KB
add.js 2KB
package.sh 1KB
layer-add.lua 3KB
add.lua 2KB
.gitignore 25B
check.js 1KB
README.md 5KB
layer-check.js 2KB
LICENSE.txt 1KB
benchmark.sh 958B
共 16 条
- 1
资源评论
快撑死的鱼
- 粉丝: 2w+
- 资源: 9148
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (175601006)51单片机交通信号灯系统设计
- Starter SINAMICS S120驱动第三方直线永磁同步电机系列视频-调试演示.mp4
- (174755032)抽烟、烟雾检测voc数据集
- 基于滑膜控制的差动制动防侧翻稳定性控制,上层通过滑膜控制产生期望的横摆力矩,下层根据对应的paper实现对应的制动力矩分配,实现车辆的防侧翻稳定性控制,通过通过carsim和simulink联合仿真
- 伺服系统基于陷波滤波器双惯量伺服系统机械谐振抑制matlab Simulink仿真 1.模型简介 模型为基于陷波滤波器的双惯量伺服系统机械谐振抑制仿真,采用Matlab R2018a Simul
- (175989002)DDR4 JESD79-4C.pdf
- lanchaoHunanHoutaiQiantai
- (177377030)Python 爬虫.zip
- (177537818)python爬虫基础知识及爬虫实例.zip
- 自动驾驶横纵向耦合控制-复现Apollo横纵向控制 基于动力学误差模型,使用mpc算法,一个控制器同时控制横向和纵向,实现横纵向耦合控制 matlab与simulink联合仿真,纵向控制已经做好油门刹
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功