Skip to content
Nuummite is a tiny persistent embedded key-value store for Crystal!
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
spec
src
.gitignore
.travis.yml
LICENSE
README.md
shard.yml

README.md

Nuummite Build Status

Nuummite is a tiny persistent embedded key-value store. All data is kept in RAM (in a Crystal Hash) and is also written to disk. So don't use Nuummite to handle big chunks of data. Keys and Values are always Strings. It just comes with the most basic operations.

Installation

Add this to your application's shard.yml:

dependencies:
  nuummite:
    github: codesteak/nuummite
    version: ~> 0.1.4

Usage

require "nuummite"

Open the database

db = Nuummite.new("path/to/folder", "optional-filename.db")

# You can also have multiple:
flowers  = Nuummite.new("flowers")
minerals = Nuummite.new("minerals")

Put some values in

db["hello"] = "world"
db["42"] = "Answer to the Ultimate Question of Life, The Universe, and Everything"
db["whitespace"] = "Hey\n\t\t :D"

Read values

db["hello"]? # => "world"
db["ehhhh"]? # => nil

#Note: db is locked while reading, so don't write to db!
db.each do |key,value|
  # reads everything
end

db["crystals/ruby"] = "9.0"
db["crystals/quartz"] = "~ 7.0"
db["crystals/nuummite"] = "5.5 - 6.0"

db.each("crystals/") do |key,value|
  # only crystals in here
end

Delete

db.delete "hello"

Garbage collect

Since values are saved to disk in a log style, file sizes grow, your key-value store needs to rewrite all data at some point:

db.garbage_collect

By default it auto garbage collects after 10_000_000 writes. To modify this behavior you can:

# garbage collects after 1000 writes or deletes
db.auto_garbage_collect_after_writes = 1000

# does not auto garbage collect
db.auto_garbage_collect_after_writes = nil  

Shutdown

You can also shutdown Nuummite by

db.shutdown

That's all you need to know 😄

Contributing

  1. Fork it ( https://github.com/codesteak/nuummite/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

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.