warrenfalk / rocksdb-sharp

.net bindings for the rocksdb by facebook
Other
208 stars 64 forks source link

StartsWith Query #63

Closed tracker1 closed 5 years ago

tracker1 commented 5 years ago

I'm wanting to return all key/value pairs that start with a given value/bytes...

For example /config/app/APPNAME/* where * is anything under that common set of starting values.

Sorry if this is otherwise handled, I'm really new to rocksdb and this library... looking to test this out as a replacement for another db that I'm using as a KV store that isn't well supported under ARM (specifically RPi).

warrenfalk commented 5 years ago

What you want is an Iterator.

RocksDb functions like a Dictionary sorted by (the binary representation of) its keys.

An Iterator is like a cursor into an immutable snapshot of the database. It supports a "Seek" operation and a "Move Next" operation. The Seek operation will put you at the lowest key that is greater than or equal to the value you seek to. So you can seek to "/config/app/appname/", check that the key returned starts with "/config/app/appname/" and if so yield it and Move Next and repeat, and keep doing this until the key doesn't start with that prefix at which point you're reached the end.

tracker1 commented 5 years ago

@warrenfalk thank you, found it in the examples... Should be able to take this and get a matching Dictionary<string,string> to return... :-)

https://github.com/warrenfalk/rocksdb-sharp/blob/aad0f20aeda1f92b42478bac495ed2e0a375385b/examples/PrefixExample/Program.cs#L50-L63