stephan-hof / pyrocksdb

Python bindings for RocksDB
BSD 3-Clause "New" or "Revised" License
150 stars 169 forks source link

Reverse seek #51

Closed bauerj closed 7 years ago

bauerj commented 7 years ago

Assume the following code:

db.put(b"key1", bytes(1))
db.put(b"key2", bytes(2))
db.put(b"key3", bytes(3))
db.put(b"key4", bytes(4))
it = db.iteritems()
it = reversed(it)
it.seek("key")
print it.__iter__().__next__()

I would expect that this prints (b'key4', b'\x00\x00\x00\x00') but the output is (b'key1', b'\x00').

Is there any way to make seek search backwards (find the last matching entry)?

Downchuck commented 7 years ago

I think you can try something like "key$" (lexographically some later character) to get what you're after.