rocksdb
rocksdb.cr
RocksDB client for Crystal.
- crystal: 0.20.0
Supported API
See API
Installation
Add this to your application's shard.yml
:
dependencies:
rocksdb:
github: maiha/rocksdb.cr
Usage
require "rocksdb"
db = RocksDB::DB.new("tmp/db1")
db.put("foo", "1")
db.get("foo") # => "1"
db.delete("foo")
db.get("foo") # => ""
db.get?("foo") # => nil
db.get!("foo") # raise RocksDB::NotFound.new("foo")
db.close
readonly mode
db = RocksDB::DB.new("tmp/db1", readonly: true)
# or RocksDB::DB.read("tmp/db1")
db.put("foo", "1") # raise RocksDB::Error("Not supported operation in read only mode.")
Iterations
3.times{|i| db.put("k#{i}", i) }
db.keys # => ["k0","k1","k2"]
db.keys(2) # => ["k0","k1"]
db.each do |(k,v)|
Iterator
iter = db.new_iterator
iter.key # => "k0"
iter.next
iter.value # => "1"
iter.first
iter.key # => "k0"
iter.seek("k2")
iter.next
iter.valid? # => false
- same as
each
iter = db.new_iterator
iter.first
while (iter.valid?)
# yield {iter.key, iter.value}
iter.next
end
binary data
Although all data are stored as Binary in RocksDB, return value will be converted to String when accessed by String key.
db.put(Bytes[0], Bytes[9])
db.get(Bytes[0]) # => Bytes[9]
db.get("\u{0}") # => "\t"
Roadmap
0.3.0
- [x]
keys
(String) - [x]
each
(String)
0.4.0
- [x] readonly mode
- [ ] Iterations for Binary
Testing
- Manual test has passed in local with
librocksdb-dev
- Unfortunately, we can't run ci on TravisCI which doesn't support ubuntu-16.04.
Contributing
- Fork it ( https://github.com/maiha/rocksdb.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- maiha maiha - creator, maintainer