Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get values from keys matching pattern in rocks db

Tags:

rust

rocksdb

Is it possible to read all values matching key pattern from rocks db. e.g:

key1 -> value1
key12 -> value12
key123 -> value123

I want to ready all keys matching pattern => "key1*" or "key*2"

Is there a way to perform this kind of search operation in Rocks Db.

like image 261
vineet pant Avatar asked Dec 11 '25 23:12

vineet pant


1 Answers

  • key1* yes: You can use rocksdb::DB::iterator with RocksDB::IteratorMode::From("key1".as_bytes(), rocksdb::Direction::Forward), and then put a .take_while(|(k, _)| k.starts_with("key1".as_bytes())) to stop it from leaving key1*.
  • key*2 no

Why is this tagged Rust?

like image 167
Caesar Avatar answered Dec 15 '25 12:12

Caesar