Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

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

About

Nuummite is a tiny persistent embedded key-value store for Crystal!

Resources

License

Packages

No packages published