Congyuwang / RocksDict

Python fast on-disk dictionary / RocksDB & SpeeDB Python binding
https://congyuwang.github.io/RocksDict/rocksdict.html
MIT License
176 stars 8 forks source link

Add key_may_exists API #55

Closed Congyuwang closed 1 year ago

Congyuwang commented 1 year ago

Check if a key may exist without doing any IO.

Notes:

If the key definitely does not exist in the database,
then this method returns False, else True.
If the caller wants to obtain value when the key is found in memory,
fetch should be set to True.
This check is potentially lighter-weight than invoking DB::get().
One way to make this lighter weight is to avoid doing any IOs.

Note that returning True doesn't mean the key definitely exists.
Moreover, if the key does not exist, it might still return True.

The key certainly exists if value is returned.
The key certainly does not exist if False is returned.

Args:

Returns:

def key_may_exist(self,
                  key: Union[str, int, float, bytes, bool],
                  fetch: bool = False,
                  read_opt = None) -> Union[bool, Tuple[bool, Any]]: ...