mbr / simplekv

A simple key-value store for binary data.
http://simplekv.readthedocs.io
MIT License
152 stars 50 forks source link

Add prefix handling to keys() and iter_keys() API #41

Closed criemen closed 7 years ago

criemen commented 7 years ago

Hi,

this PR adds prefix handling to the keys() and iter_keys() API. When the user specifies a non-empty prefix, only keys starting with that prefix are returned.

This API is mainly useful when implementing/emulating file systems or other hierarchical structures on top of a KV store, as a prefix can be interpreted as a directory and the keys() call lists all "files" within such a directory. Some backends implement this server-side, leading to increased efficiency, as we do not have to transfer all keys available from the backend to python and then filtering, but directly filtering on the server. If there is no server-side filtering available, the filtering can be done in python, not leading to efficiency gains, but nonetheless being correct.

This depends on #39 for green tests.

fmarczin commented 7 years ago

Although this adds stuff to the core API, I'm in favor of this, since adding it there is the only way to pass the prefix to the backend and allow it to implement this efficiently, i.e. asking only for matching keys.