redis rebloom 报错 Maximum expansions reached

使用 rebloom 遇到了报错:redis.exceptions.ResponseError: Maximum expansions reached

具体内容如下:

  File "/usr/local/lib/python3.10/site-packages/redisbloom/client.py", line 411, in cfAddNX
    return self.execute_command(self.CF_ADDNX, *params)
           │    │               │    │          └ ['crawler', 'https://power.in-en.com/html/power-2402142.shtml']
           │    │               │    └ 'CF.ADDNX'
           │    │               └ Client>>
           │    └ 
           └ Client>>
  File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 901, in execute_command
    return self.parse_response(conn, command_name, **options)
           │    │              │     │               └ {}
           │    │              │     └ 'CF.ADDNX'
           │    │              └ Connection
           │    └ 
           └ Client>>
  File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 915, in parse_response
    response = connection.read_response()
               │          └ 
               └ Connection
  File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 756, in read_response
    raise response
          └ ResponseError('Maximum expansions reached')

redis.exceptions.ResponseError: Maximum expansions reached

问题原因:布隆过滤器的容量满了

解决方案:

如果你是用 redis cli,就先删除 key,再重新创建 key。用这个命令创建 CF.RESERVE,具体参考:CF.RESERVE

比如 CF.RESERVE crawler 100000000 就是创建一个容量为一亿的布隆过滤器

当然,这个容量到底用多少,需要自己评估

如果你要查看当前布隆过滤器的容量大小,就用 CF.INFO 命令,比如:

127.0.0.1:6379> CF.INFO clip_url_hash
 1) "Size"
 2) "16777272"
 3) "Number of buckets"
 4) "8388608"
 5) "Number of filters"
 6) "1"
 7) "Number of items inserted"
 8) "21436"
 9) "Number of items deleted"
10) "0"
11) "Bucket size"
12) "2"
13) "Expansion rate"
14) "1"
15) "Max iterations"
16) "20"

如果你是用 python, 可以按照下面的代码来创建新的 key

from redisbloom.client import Client
import settings

client = Client(
    host=settings.REDIS_CONFIG.host,
    port=settings.REDIS_CONFIG.port,
    db=settings.REDIS_CONFIG.db
)

def create_filter():
    client.cfCreate(key, 1000000000)

你可能感兴趣的:(redis)