rochefort 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rochefort.rb +29 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c17f990804b13617208ac9c09942132e1a39f81b
|
4
|
+
data.tar.gz: 236b07c56d3f1d41c1f96454dca068f780291c44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39231ec80b8bf881175558612c67e33504098c90e203c663dbcda06f3820bfe0e1d663c2da25932c4ce8bc4fca4676bed7ac9c57c916424c2fc40e414324d286
|
7
|
+
data.tar.gz: 7d6e979c8c8d6496d52896284895dcbcc4d7784df07955897687ab9f3cb91ebe48b93af521b00e95f15d3f1eed1293df6f6db8e53419c3f217b94f2ac2a712f5
|
data/lib/rochefort.rb
CHANGED
@@ -5,12 +5,13 @@ require 'json'
|
|
5
5
|
# client for https://github.com/jackdoe/rochefort - disk speed append + offset service (poor man's kafka),
|
6
6
|
# example usage
|
7
7
|
# r = new Rochefort("http://localhost:8001")
|
8
|
-
# offset = r.append("example-namespace", "example-
|
9
|
-
# p r.get("example-namespace",offset)
|
8
|
+
# offset = r.append(namespace: "example-namespace", data:"example-data")
|
9
|
+
# p r.get(namespace: "example-namespace", offset: offset)
|
10
10
|
class Rochefort
|
11
11
|
# @param url - the rochefort url (String)
|
12
12
|
def initialize(url)
|
13
|
-
@
|
13
|
+
@urlAppend = URI::join(url,'append').to_s
|
14
|
+
@urlModify = URI::join(url,'modify').to_s
|
14
15
|
@urlGet = URI::join(url,'get').to_s
|
15
16
|
@urlScan = URI::join(url,'scan').to_s
|
16
17
|
@urlGetMulti = URI::join(url,'getMulti').to_s
|
@@ -21,13 +22,14 @@ class Rochefort
|
|
21
22
|
# r.append(
|
22
23
|
# namespace: "ns", # default nil (nil means the default namespace)
|
23
24
|
# data: "some data", # the data you want to append
|
25
|
+
# alloc_size: 1024, # you can allocate more space and then modify it, or 0 for len(data)
|
24
26
|
# read_timeout: 1, # default 1
|
25
27
|
# open_timeout: 1, # default 1
|
26
28
|
# )
|
27
29
|
# @return the offset at which the data was stored
|
28
30
|
def append(opts)
|
29
31
|
data = RestClient::Request.execute(method: :post,
|
30
|
-
url: "#{@
|
32
|
+
url: "#{@urlAppend}?namespace=#{opts[:namespace]}&allocSize=#{opts[:alloc_size]}",
|
31
33
|
payload: opts[:data],
|
32
34
|
read_timeout: opts[:read_timeout] || 1,
|
33
35
|
open_timeout: opts[:open_timeout] || 1)
|
@@ -35,6 +37,29 @@ class Rochefort
|
|
35
37
|
return out["offset"]
|
36
38
|
end
|
37
39
|
|
40
|
+
|
41
|
+
# modify inplace
|
42
|
+
# r = Rochefort.new(url)
|
43
|
+
# r.modify(
|
44
|
+
# namespace: "ns", # default nil (nil means the default namespace)
|
45
|
+
# data: "some data", # the data you want to append
|
46
|
+
# offset: 1024, # appended offset you want to modify
|
47
|
+
# position: 10, # position within the blob you want to replace with 'data'
|
48
|
+
# read_timeout: 1, # default 1
|
49
|
+
# open_timeout: 1, # default 1
|
50
|
+
# )
|
51
|
+
# @return the offset at which the data was stored
|
52
|
+
def modify(opts)
|
53
|
+
data = RestClient::Request.execute(method: :post,
|
54
|
+
url: "#{@urlModify}?namespace=#{opts[:namespace]}&offset=#{opts[:offset]}&pos=#{opts[:position]}",
|
55
|
+
payload: opts[:data],
|
56
|
+
read_timeout: opts[:read_timeout] || 1,
|
57
|
+
open_timeout: opts[:open_timeout] || 1)
|
58
|
+
out = JSON.parse(data.body)
|
59
|
+
return out["success"]
|
60
|
+
end
|
61
|
+
|
62
|
+
|
38
63
|
# get data from rochefort
|
39
64
|
# r = Rochefort.new(url)
|
40
65
|
# r.get(
|