rocksdb-ffi 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +14 -1
- data/lib/rocksdb/version.rb +1 -1
- data/lib/rocksdb.rb +35 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 691b849562ba32f10bb834756ddbc9a7bae89af2b06f51d272fcde575eeb23e4
|
4
|
+
data.tar.gz: b8b66067cd541f59d856aa915d7737f515164349e68ac03c694e5b3280fd0e19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48ebff505cd2f1d3a98fb7371d5b2b5d121d262dff1e4366a79d8e01198d42a85c841a35b746d3782294643b543905839016a655eb7bd565b9fdc9aee346d5f5
|
7
|
+
data.tar.gz: 6385d064e46e67afefd3497ab5d4b676edf5dedda9eb1b276e40cf1e00d668833871c15eb5c34d86f91139146b95e53e637865e5ec0f8616cbac403f5ef426cf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -36,12 +36,25 @@ rocksdb.each_key do |key|
|
|
36
36
|
# ...
|
37
37
|
end
|
38
38
|
|
39
|
+
rocksdb.each_prefix("prefix") do |key, value|
|
40
|
+
# ...
|
41
|
+
end
|
42
|
+
|
43
|
+
rocksdb.flush
|
44
|
+
|
39
45
|
rocksdb.close
|
40
46
|
|
41
47
|
rocksdb.open("/path/to/other/db")
|
42
48
|
```
|
43
49
|
|
44
|
-
The library is tested against
|
50
|
+
The library is tested against:
|
51
|
+
|
52
|
+
* ruby 2.7 with rocksdb 7.2
|
53
|
+
* ruby 3.0 with rocksdb 7.2
|
54
|
+
* ruby 3.1 with rocksdb 7.2
|
55
|
+
* ruby 3.1 with rocksdb 7.7
|
56
|
+
* ruby 3.2 with rocksdb 7.2
|
57
|
+
* ruby 3.2 with rocksdb 7.7
|
45
58
|
|
46
59
|
## Thread-safety
|
47
60
|
|
data/lib/rocksdb/version.rb
CHANGED
data/lib/rocksdb.rb
CHANGED
@@ -24,6 +24,7 @@ class RocksDB
|
|
24
24
|
attach_function :rocksdb_create_iterator, [:pointer, :pointer], :pointer
|
25
25
|
attach_function :rocksdb_iter_valid, [:pointer], :uchar
|
26
26
|
attach_function :rocksdb_iter_seek_to_first, [:pointer], :void
|
27
|
+
attach_function :rocksdb_iter_seek, [:pointer, :string, :size_t], :void
|
27
28
|
attach_function :rocksdb_iter_next, [:pointer], :void
|
28
29
|
attach_function :rocksdb_iter_key, [:pointer, :pointer], :pointer
|
29
30
|
attach_function :rocksdb_iter_value, [:pointer, :pointer], :pointer
|
@@ -164,6 +165,19 @@ class RocksDB
|
|
164
165
|
end
|
165
166
|
end
|
166
167
|
|
168
|
+
def each_prefix(prefix)
|
169
|
+
raise(ClosedError, "Database is closed") if @closed
|
170
|
+
|
171
|
+
return enum_for(__method__, prefix) unless block_given?
|
172
|
+
|
173
|
+
iterate_prefix(prefix) do |key, iterator|
|
174
|
+
value_length = FFI::MemoryPointer.new(:size_t, 1)
|
175
|
+
value = read_string(Lib.rocksdb_iter_value(iterator, value_length), value_length)
|
176
|
+
|
177
|
+
yield(key, value)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
167
181
|
private
|
168
182
|
|
169
183
|
def iterate
|
@@ -182,6 +196,27 @@ class RocksDB
|
|
182
196
|
end
|
183
197
|
end
|
184
198
|
|
199
|
+
def iterate_prefix(prefix)
|
200
|
+
iterator = Lib.rocksdb_create_iterator(@db, @read_options)
|
201
|
+
|
202
|
+
begin
|
203
|
+
Lib.rocksdb_iter_seek(iterator, prefix, prefix.bytesize)
|
204
|
+
|
205
|
+
while Lib.rocksdb_iter_valid(iterator) != 0
|
206
|
+
key_length = FFI::MemoryPointer.new(:size_t, 1)
|
207
|
+
key = read_string(Lib.rocksdb_iter_key(iterator, key_length), key_length)
|
208
|
+
|
209
|
+
return unless key.start_with?(prefix)
|
210
|
+
|
211
|
+
yield(key, iterator)
|
212
|
+
|
213
|
+
Lib.rocksdb_iter_next(iterator)
|
214
|
+
end
|
215
|
+
ensure
|
216
|
+
Lib.rocksdb_iter_destroy(iterator)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
185
220
|
def check_error(error)
|
186
221
|
pointer = error.read_pointer
|
187
222
|
return if pointer.null?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocksdb-ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|