下载
安装使用
mkdir -p /data/server/wordsFilter
cd /data/server/wordsFilter
wget -O goRedisWordsFilter-v0.0.1.tar.gz https://github.com/jonnywang/goRedisWordsFilter/files/2334417/goRedisWordsFilter-v0.0.1.tar.gz
tar zxvf goRedisWordsFilter-v0.0.1.tar.gz
cd v0.0.1
./bin/goRedisWordsFilter_linux --config=conf/config.xml
配置说明
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<!-- redis server -->
<server>0.0.0.0:8299</server>
<!-- 脏字字典 -->
<dict>dict/words.conf</dict>
</config>
字典格式以行为单位填写待过滤脏字
毛片
妈的
命令
redis-cli -p 8299 --raw
127.0.0.1:8299> total
2
127.0.0.1:8299> exists 好x
0
127.0.0.1:8299> add 好x
OK
127.0.0.1:8299> total
3
127.0.0.1:8299> filter 妈的-我看他说话的语气,好x啊
**-我看他说话的语气,**啊
127.0.0.1:8299> delete 妈的
OK
127.0.0.1:8299> total
2
127.0.0.1:8299> filter 妈的-我看他说话的语气,好x啊
妈的-我看他说话的语气,**啊
127.0.0.1:8299> reload
OK
127.0.0.1:8299> total
3
127.0.0.1:8299> exists 好x
1
127.0.0.1:8299> filter 妈的-我看他说话的语气,好x啊
**-我看他说话的语气,**啊
127.0.0.1:8299> FLUSHALL
OK
127.0.0.1:8299> total
0
127.0.0.1:8299> reload
OK
127.0.0.1:8299> total
3
127.0.0.1:8299> filter 妈的-我看他说话的语气,好x啊
**-我看他说话的语气,**啊
用例
<?php
$redis_handle = new Redis();
$redis_handle->connect('127.0.0.1', 8299, 10);
$result = $redis_handle->rawCommand('filter', '妈的-我看他说话的语气,好x啊');
echo $result . PHP_EOL;
$result = $redis_handle->rawCommand('add', '好x');
var_dump($result);
$result = $redis_handle->rawCommand('add', '好x');
var_dump($result);
$result = $redis_handle->rawCommand('filter', '妈的-我看他说话的语气,好x啊');
echo $result . PHP_EOL;
测试
php test_filter.php
**-我看他说话的语气,好x啊
bool(true)
bool(false)
**-我看他说话的语气,**啊
支持