“Bloom filter”与“Vertx: Future异步操作设计”:页面之间的差异

来自WHY42
(页面间差异)
无编辑摘要
 
(建立內容為「=Future相关操作的设计= == AsyncResult == AsyncResult表示一个异步操作的结果,这个结果要么是成功的,要么是失败的。 <syntaxhighl…」的新頁面)
 
第1行: 第1行:
RedisBloom provides Redis with support for additional probabilistic data structures. These structures allow for constant memory space and extremely fast processing while still maintaining a low error rate. It supports scalable Bloom and Cuckoo filters to determine whether an item is present or absent from a collection with a given degree of certainty, Count-min sketch to count the frequency of the different items in sub-linear space, and Top-K to count top k events in a near deterministic manner.
=Future相关操作的设计=
 
== AsyncResult ==
A good use case for a Bloom filter is to check for an already used username. On a small scale, this is no problem, but as a service grows, this can be very taxing on a database. It is very simple to implement this with a ReBloom.
AsyncResult表示一个异步操作的结果,这个结果要么是成功的,要么是失败的。
 
<syntaxhighlight lang="java">
 
interface AsyncResult<T> {
<syntaxhighlight lang="lisp">
    T getResult();
> BF.ADD usernames funnyfred
    Throwable cause();
(integer) 1
    boolean succeeded();
> BF.ADD usernames fredisfunny
    boolean failed();
(integer) 1
    AsyncResult<V> map(Function<T, V> mapper);
> BF.ADD usernames fred
    AsyncResult<V> map(V value);
(integer) 1
    AsyncResult<V> mapEmpty();
> BF.ADD usernames funfred
    AsyncResult<T> otherwise(T value);
(integer) 1
    AsyncResult<T> otherwise(Function<Throwable, T> mapper);
</syntaxhighlight>
    AsyncResult<T> otherwiseEmpty();
 
}
<syntaxhighlight lang="lisp">
> BF.EXISTS usernames fred
(integer) 1
> BF.EXISTS usernames fred_is_funny
(integer) 0
</syntaxhighlight>
</syntaxhighlight>




As expected, fred_is_funny yields a 0. A response of zero means we can be sure that this username has not been used. A response of 1 means it might have been used. We can’t say for certain as it might a case of overlapping bits between multiple items.


Generally, the chances of false positives are low, but non-zero. As the Bloom filter “fills up” the chances increase. You can tweak the error rate and size with the BF.RESERVE command.
[[Category:Vert.x]]
[[Category:Database]]
[[Category:Redis]]

2021年7月25日 (日) 08:04的版本

Future相关操作的设计

AsyncResult

AsyncResult表示一个异步操作的结果,这个结果要么是成功的,要么是失败的。

interface AsyncResult<T> {
    T getResult();
    Throwable cause();
    boolean succeeded();
    boolean failed();
    AsyncResult<V> map(Function<T, V> mapper);
    AsyncResult<V> map(V value);
    AsyncResult<V> mapEmpty();
    AsyncResult<T> otherwise(T value);
    AsyncResult<T> otherwise(Function<Throwable, T> mapper);
    AsyncResult<T> otherwiseEmpty();
}