0.0
No commit activity in last 3 years
No release in over 3 years
Curator to Manage multiple LevelDB databases over UDP. See project home (GIT) for implementation details.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

LevelDB Curator

The LevelDB Curator gem allows you to manage one or more LevelDB databases from one or more clients concurrently. It listens on UDP port 9068 on localhost for put and get commands.

Installation

bundle install
gem build leveldb_curator.gemspec
gem install ./leveldb_curator-0.1.0.gem

Example server implementation

require "leveldb_curator"

LeveldbCurator.new(
  %w(foobar_database barfoo_database)
)

The above example will initialize two leveldb databases: foobar_database and barfoo_database. It will keep running until the process is terminated.

Example client implementation

require 'socket'
require 'bindata'

class Protocol < BinData::Record
    endian  :big
    stringz :database
    stringz :command_word
    stringz :query_key
    stringz :query_value
end

def get_answer(sock)
    msg, sender = sock.recvfrom(1024)
    msg
end

def send_request(sock, data)
    sock.send(data, 0, "localhost", 9068)
end

def query(database, command, query_key, query_value = "")
    add_request = Protocol.new
    add_request.database = database
    add_request.command_word = command
    add_request.query_key = query_key
    add_request.query_value = query_value
    send_request(@s, add_request.to_binary_s)
    get_answer(@s)
end

@s = UDPSocket.new

query("foobar_database", "put", "foo", "bar")
query("barfoo_database", "put", "bar", "foo")
response = query("foobar_database", "get", "foo")
response2 = query("barfoo_database", "get", "bar")

puts response
puts response2

The client code does not depend on this gem nor on leveldb. It only sends out UDP queries and returns the daemon's response. Therefore you can use this in multiple projects querying the same database.

Credits

I've borrowed the UDP client/server code from this gist:

https://gist.github.com/omnisis/3998752

Thanks to [@omnisis] for posting it.