leveldb_curator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/leveldb_curator.rb +55 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1efeaec24928ba0db3fe90bf4eb06b80cd949efa
|
4
|
+
data.tar.gz: fb44dde953ca298838a224e5bd8278aa450dd17c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e0282a658a1ceae7cb5a74e8966c971650243b6e1d5059d67f5edc481c45474d9c786f450ca65175d294d0c9207ba05ca50680d0c3333f933cfc19b3911d5ce
|
7
|
+
data.tar.gz: 72f876709c4827fe99df4bd9aeea44c81170703d93b9043aa1958e39afbd8ac54cba2a48d7b99a49592f0c4db5d4a7cb64b8b3c37f4caed1937a9b3889c9bb5c
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "leveldb"
|
2
|
+
require "socket"
|
3
|
+
require "bindata"
|
4
|
+
|
5
|
+
class Protocol < BinData::Record
|
6
|
+
endian :big
|
7
|
+
stringz :database
|
8
|
+
stringz :command_word
|
9
|
+
stringz :query_key
|
10
|
+
stringz :query_value
|
11
|
+
end
|
12
|
+
|
13
|
+
class LeveldbCurator
|
14
|
+
def open_databases(databases)
|
15
|
+
db_list = {}
|
16
|
+
databases.each do |database|
|
17
|
+
dbh = LevelDB::DB.new(database)
|
18
|
+
db_list[database.to_sym] = dbh
|
19
|
+
end
|
20
|
+
db_list
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_daemon(port, databases)
|
24
|
+
unless databases.kind_of?(Array)
|
25
|
+
databases = [databases]
|
26
|
+
end
|
27
|
+
db_handlers = open_databases(databases)
|
28
|
+
Socket.udp_server_loop("localhost", port) { |msg, msg_src|
|
29
|
+
proto = Protocol.new
|
30
|
+
proto.read(msg)
|
31
|
+
|
32
|
+
dbh = db_handlers[proto.database.to_sym]
|
33
|
+
if proto.command_word == "put"
|
34
|
+
begin
|
35
|
+
dbh.put(proto.query_key, proto.query_value)
|
36
|
+
msg_src.reply "true"
|
37
|
+
rescue => exception
|
38
|
+
msg_src.reply exception.to_s
|
39
|
+
end
|
40
|
+
elsif proto.command_word == "get"
|
41
|
+
begin
|
42
|
+
msg_src.reply dbh.get(proto.query_key)
|
43
|
+
rescue
|
44
|
+
msg_src.reply ""
|
45
|
+
end
|
46
|
+
else
|
47
|
+
msg_src.reply "invalid command"
|
48
|
+
end
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize(databases = "my_leveldb_database")
|
53
|
+
run_daemon(9068, databases)
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leveldb_curator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Vink
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Curator to Manage multiple LevelDB databases over UDP
|
14
|
+
email: dennis@drvink.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/leveldb_curator.rb
|
20
|
+
homepage: http://rubygems.org/gems/leveldb_curator
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Curator for managing LevelDB over UDP
|
44
|
+
test_files: []
|