Project

gnista

0.02
No commit activity in last 3 years
No release in over 3 years
Gnista is a wrapper for the database/hashstore Sparkey written for Ruby. Gnista packs all the native features of Sparkey into a shiny red package, easy to use.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

Gnista

Gnista is a wrapper for the database/hashstore Sparkey written for Ruby. Gnista packs all the native features of Sparkey into a shiny red package, easy to use.

Setup

You will need Sparkey, obviously. It's really easy to install. Head over to http://github.com/spotify/sparkey and install it, I'll wait..

Now, add this line to your application's Gemfile:

gem 'gnista'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gnista

Usage

You can read about Sparkey here.

require 'gnista'

logwriter = Gnista::Logwriter.new "mylog.log" # no compression
logwriter = Gnista::Logwriter.new "mylog.log", 4000 # 4k compression block size
logwriter = Gnista::Logwriter.new "mylog.log", :append # append to existing log

logwriter.logpath # => "mylog.log"

logwriter.put "key", "value" # put entry
logwriter["key"] = "value"
logwriter.del "key" # delete entry
logwriter.flush

logwriter.write_batch do
  logwriter["key1"] = "value1"
  logwriter["key2"] = "value2"
end


logreader = Gnista::Logreader.new "mylog.log"
logreader.logpath # => "mylog.log"

logreader.each {|key,value,type| puts key, value, type }
# => "key", "value"/nil, :put/:delete

logreader.maxkeylen # largest key length
logreader.maxkeylen # largest value length


Gnista::Hash.write "mylog.hash", "mylog.log" # no preferred hash size
Gnista::Hash.write "mylog.hash", "mylog.log", 4 # 32 bit murmurhash3_x86_32
Gnista::Hash.write "mylog.hash", "mylog.log", 8 # lower 64-bit part of murmurhash3_x64_128

hash = Gnista::Hash.new "mylog.hash", "mylog.log"
logwriter.hashpath # => "mylog.hash"
logwriter.logpath # => "mylog.log"

hash.each {|key,value| puts key, value }
hash.get "key" # => "value" or nil
hash["key"]

hash.maxkeylen
hash.maxkeylen
hash.length
hash.collisions
hash.empty?
hash.include? "key"
hash.keys # => ["key1", "key2"]
hash.values # => ["value1", "value2"]


# Don't forget to close!
logwriter.close
logreader.close
hash.close

logwriter.open? || logreader.open? || hash.open? # => false

Both Logreaderand Hash mixin Enumerable.

Contributing

Step-by-step:

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write some code
  4. Build and test
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create new Pull Request

Use the following commands to build the native extensions and test:

$ rake make
$ rake test