Code Monkey home page Code Monkey logo

rocksdb.cr's Introduction

rocksdb.cr Build Status

RocksDB client for Crystal.

  • crystal: 0.24.2

Supported API

See API

Installation

Add this to your application's shard.yml:

dependencies:
  rocksdb:
    github: maiha/rocksdb.cr
    version: 0.5.1

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

iter.close  # memory leaks when you forget this
  • same as each
iter = db.new_iterator
iter.first
while (iter.valid?)
  # yield {iter.key, iter.value}
  iter.next
end  
iter.close  # memory leaks when you forget this

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"

binary iterator

binary_XXX is available to treat data as binary

  • binary_keys
  • binary_each
  • new_binary_iterator
db.keys        # => ["\t"]
db.binary_keys # => [Bytes[9]]

database options

  • options for opening database
  • read_options for reading data
  • write_options for writing data
opts = RocksDB::Options.new
opts.set_create_if_missing(1)

ropts = RocksDB::ReadOptions.new
ropts.set_verify_checksum(1)

wopts = RocksDB::WriteOptions.new
wopts.set_sync(1)
wopts.disable_wal(1)

db = RocksDB::DB.new("tmp/db1", options: opts, read_options: ropts, write_options: wopts)

Roadmap

0.5.0

  • Iterations for Binary

Testing

  • Now Travis CI is ready by maiha#3

Contributing

  1. Fork it ( https://github.com/maiha/rocksdb.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • maiha maiha - creator, maintainer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.