RedisBloom 命令

以下是与 RedisBloom 模块 交互的命令。下面是一个简要的示例,以及相关命令的文档。

创建并添加到布隆过滤器(Create and add to a bloom filter)

import redis
r = redis.Redis()
r.bf().create("bloom", 0.01, 1000)
r.bf().add("bloom", "foo")

创建并添加到布谷鸟过滤器(Create and add to a cuckoo filter)

import redis
r = redis.Redis()
r.cf().create("cuckoo", 1000)
r.cf().add("cuckoo", "filter")

创建 Count-Min Sketch 并获取信息(Create Count-Min Sketch and get information)

import redis
r = redis.Redis()
r.cms().initbydim("dim", 1000, 5)
r.cms().incrby("dim", ["foo"], [5])
r.cms().info("dim")

创建一个 topk 列表,并访问结果(Create a topk list, and access the results)

import redis
r = redis.Redis()
r.topk().reserve("mytopk", 3, 50, 4, 0.9)
r.topk().info("mytopk")
class redis.commands.bf.commands.BFCommands[源代码]

Bloom Filter commands.

add(key, item)[源代码]

Add to a Bloom Filter key an item. For more information see BF.ADD.

card(key)[源代码]

Returns the cardinality of a Bloom filter - number of items that were added to a Bloom filter and detected as unique (items that caused at least one bit to be set in at least one sub-filter). For more information see BF.CARD.

create(key, errorRate, capacity, expansion=None, noScale=None)[源代码]

Create a new Bloom Filter key with desired probability of false positives errorRate expected entries to be inserted as capacity. Default expansion value is 2. By default, filter is auto-scaling. For more information see BF.RESERVE.

exists(key, item)[源代码]

Check whether an item exists in Bloom Filter key. For more information see BF.EXISTS.

info(key)[源代码]

Return capacity, size, number of filters, number of items inserted, and expansion rate. For more information see BF.INFO.

insert(key, items, capacity=None, error=None, noCreate=None, expansion=None, noScale=None)[源代码]

Add to a Bloom Filter key multiple items.

If nocreate remain None and key does not exist, a new Bloom Filter key will be created with desired probability of false positives errorRate and expected entries to be inserted as size. For more information see BF.INSERT.

loadchunk(key, iter, data)[源代码]

Restore a filter previously saved using SCANDUMP.

See the SCANDUMP command for example usage. This command will overwrite any bloom filter stored under key. Ensure that the bloom filter will not be modified between invocations. For more information see BF.LOADCHUNK.

madd(key, *items)[源代码]

Add to a Bloom Filter key multiple items. For more information see BF.MADD.

mexists(key, *items)[源代码]

Check whether items exist in Bloom Filter key. For more information see BF.MEXISTS.

reserve(key, errorRate, capacity, expansion=None, noScale=None)

Create a new Bloom Filter key with desired probability of false positives errorRate expected entries to be inserted as capacity. Default expansion value is 2. By default, filter is auto-scaling. For more information see BF.RESERVE.

scandump(key, iter)[源代码]

Begin an incremental save of the bloom filter key.

This is useful for large bloom filters which cannot fit into the normal SAVE and RESTORE model. The first time this command is called, the value of iter should be 0. This command will return successive (iter, data) pairs until (0, NULL) to indicate completion. For more information see BF.SCANDUMP.

class redis.commands.bf.commands.CFCommands[源代码]

Cuckoo Filter commands.

add(key, item)[源代码]

Add an item to a Cuckoo Filter key. For more information see CF.ADD.

addnx(key, item)[源代码]

Add an item to a Cuckoo Filter key only if item does not yet exist. Command might be slower that add. For more information see CF.ADDNX.

count(key, item)[源代码]

Return the number of times an item may be in the key. For more information see CF.COUNT.

create(key, capacity, expansion=None, bucket_size=None, max_iterations=None)[源代码]

Create a new Cuckoo Filter key an initial capacity items. For more information see CF.RESERVE.

delete(key, item)[源代码]

Delete item from key. For more information see CF.DEL.

exists(key, item)[源代码]

Check whether an item exists in Cuckoo Filter key. For more information see CF.EXISTS.

info(key)[源代码]

Return size, number of buckets, number of filter, number of items inserted, number of items deleted, bucket size, expansion rate, and max iteration. For more information see CF.INFO.

insert(key, items, capacity=None, nocreate=None)[源代码]

Add multiple items to a Cuckoo Filter key, allowing the filter to be created with a custom capacity if it does not yet exist. items must be provided as a list. For more information see CF.INSERT.

insertnx(key, items, capacity=None, nocreate=None)[源代码]

Add multiple items to a Cuckoo Filter key only if they do not exist yet, allowing the filter to be created with a custom capacity if it does not yet exist. items must be provided as a list. For more information see CF.INSERTNX.

loadchunk(key, iter, data)[源代码]

Restore a filter previously saved using SCANDUMP. See the SCANDUMP command for example usage.

This command will overwrite any Cuckoo filter stored under key. Ensure that the Cuckoo filter will not be modified between invocations. For more information see CF.LOADCHUNK.

mexists(key, *items)[源代码]

Check whether an items exist in Cuckoo Filter key. For more information see CF.MEXISTS.

reserve(key, capacity, expansion=None, bucket_size=None, max_iterations=None)

Create a new Cuckoo Filter key an initial capacity items. For more information see CF.RESERVE.

scandump(key, iter)[源代码]

Begin an incremental save of the Cuckoo filter key.

This is useful for large Cuckoo filters which cannot fit into the normal SAVE and RESTORE model. The first time this command is called, the value of iter should be 0. This command will return successive (iter, data) pairs until (0, NULL) to indicate completion. For more information see CF.SCANDUMP.

class redis.commands.bf.commands.CMSCommands[源代码]

Count-Min Sketch Commands

incrby(key, items, increments)[源代码]

Add/increase items to a Count-Min Sketch key by ''increments''. Both items and increments are lists. For more information see CMS.INCRBY.

Example:

>>> cmsincrby('A', ['foo'], [1])
info(key)[源代码]

Return width, depth and total count of the sketch. For more information see CMS.INFO.

initbydim(key, width, depth)[源代码]

Initialize a Count-Min Sketch key to dimensions (width, depth) specified by user. For more information see CMS.INITBYDIM.

initbyprob(key, error, probability)[源代码]

Initialize a Count-Min Sketch key to characteristics (error, probability) specified by user. For more information see CMS.INITBYPROB.

merge(destKey, numKeys, srcKeys, weights=[])[源代码]

Merge numKeys of sketches into destKey. Sketches specified in srcKeys. All sketches must have identical width and depth. Weights can be used to multiply certain sketches. Default weight is 1. Both srcKeys and weights are lists. For more information see CMS.MERGE.

query(key, *items)[源代码]

Return count for an item from key. Multiple items can be queried with one call. For more information see CMS.QUERY.

class redis.commands.bf.commands.TOPKCommands[源代码]

TOP-k Filter commands.

add(key, *items)[源代码]

Add one item or more to a Top-K Filter key. For more information see TOPK.ADD.

count(key, *items)[源代码]

Return count for one item or more from key. For more information see TOPK.COUNT.

incrby(key, items, increments)[源代码]

Add/increase items to a Top-K Sketch key by ''increments''. Both items and increments are lists. For more information see TOPK.INCRBY.

Example:

>>> topkincrby('A', ['foo'], [1])
info(key)[源代码]

Return k, width, depth and decay values of key. For more information see TOPK.INFO.

list(key, withcount=False)[源代码]

Return full list of items in Top-K list of key. If withcount set to True, return full list of items with probabilistic count in Top-K list of key. For more information see TOPK.LIST.

query(key, *items)[源代码]

Check whether one item or more is a Top-K item at key. For more information see TOPK.QUERY.

reserve(key, k, width, depth, decay)[源代码]

Create a new Top-K Filter key with desired probability of false positives errorRate expected entries to be inserted as size. For more information see TOPK.RESERVE.