libcouchbase 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/libcouchbase/bucket.rb +8 -34
- data/lib/libcouchbase/connection.rb +15 -50
- data/lib/libcouchbase/query_view.rb +1 -1
- data/lib/libcouchbase/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbbca533b435a70a968e4db6b7105061cf6a5c4c
|
4
|
+
data.tar.gz: 8da2a213ffe1262897d76e77d267468272262839
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27673bc5a39dbc17238f941a4124e70f43ab3823258d23258ac2fe2c3dcad221b3d28c6c040cd32aee00b70e772f2b08f9747aeb1abb4f6a4f3f5309bbe7f20b
|
7
|
+
data.tar.gz: a74d898f35f5907c42e1ef62055b010100496614c72405bb2873755e79739f6f242ddf0d8bfa80f634d1e62ea5b0175d03ccc15389dc86ac9dd54fd697fd7bef
|
data/lib/libcouchbase/bucket.rb
CHANGED
@@ -48,8 +48,6 @@ module Libcouchbase
|
|
48
48
|
# @option options [true, false] :quiet (self.quiet) If set to +true+, the
|
49
49
|
# operation won't raise error for missing key, it will return +nil+.
|
50
50
|
# Otherwise it will raise a not found error.
|
51
|
-
# @option options [Symbol] :format the value should be stored as.
|
52
|
-
# Defaults to :document
|
53
51
|
# @option options [true, false] :assemble_hash (false) Assemble Hash for
|
54
52
|
# results.
|
55
53
|
#
|
@@ -182,7 +180,6 @@ module Libcouchbase
|
|
182
180
|
# @option options [Integer] :expire_in Expiry time for key in seconds
|
183
181
|
# @option options [Integer, Time] :expire_at Unix epoc or time at which a key
|
184
182
|
# should expire
|
185
|
-
# @option options [Symbol] :format the value should be stored as.
|
186
183
|
# @option options [Integer] :cas The CAS value for an object. This value is
|
187
184
|
# created on the server and is guaranteed to be unique for each value of
|
188
185
|
# a given key. This value is used to provide simple optimistic
|
@@ -205,10 +202,7 @@ module Libcouchbase
|
|
205
202
|
# @example Store the key which will be expired in 2 seconds using absolute TTL.
|
206
203
|
# c.add(:foo, :bar, expire_at: Time.now.to_i + 2)
|
207
204
|
#
|
208
|
-
# @example
|
209
|
-
# c.add("foo", {"bar" => "baz"}, format: :document)
|
210
|
-
#
|
211
|
-
# @example Set application specific flags (note that it will be OR-ed with format flags)
|
205
|
+
# @example Set application specific flags
|
212
206
|
# c.add("foo", "bar", flags: 0x1000)
|
213
207
|
#
|
214
208
|
# @example Ensure that the key will be persisted at least on the one node
|
@@ -227,7 +221,6 @@ module Libcouchbase
|
|
227
221
|
# @option options [Integer] :expire_in Expiry time for key in seconds
|
228
222
|
# @option options [Integer, Time] :expire_at Unix epoc or time at which a key
|
229
223
|
# should expire
|
230
|
-
# @option options [Symbol] :format the value should be stored as.
|
231
224
|
# @option options [Integer] :cas The CAS value for an object. This value is
|
232
225
|
# created on the server and is guaranteed to be unique for each value of
|
233
226
|
# a given key. This value is used to provide simple optimistic
|
@@ -251,13 +244,10 @@ module Libcouchbase
|
|
251
244
|
# @example Store the key which will be expired in 2 seconds using absolute TTL.
|
252
245
|
# c.set(:foo, :bar, expire_at: Time.now.to_i + 2)
|
253
246
|
#
|
254
|
-
# @example Force JSON document format for value
|
255
|
-
# c.set("foo", {"bar" => "baz"}, format: :document)
|
256
|
-
#
|
257
247
|
# @example Use hash-like syntax to store the value
|
258
248
|
# c[:foo] = {bar: :baz}
|
259
249
|
#
|
260
|
-
# @example Set application specific flags
|
250
|
+
# @example Set application specific flags
|
261
251
|
# c.set("foo", "bar", flags: 0x1000)
|
262
252
|
#
|
263
253
|
# @example Perform optimistic locking by specifying last known CAS version
|
@@ -280,7 +270,6 @@ module Libcouchbase
|
|
280
270
|
# @option options [Integer] :expire_in Expiry time for key in seconds
|
281
271
|
# @option options [Integer, Time] :expire_at Unix epoc or time at which a key
|
282
272
|
# should expire
|
283
|
-
# @option options [Symbol] :format the value should be stored as.
|
284
273
|
# @option options [Integer] :cas The CAS value for an object. This value is
|
285
274
|
# created on the server and is guaranteed to be unique for each value of
|
286
275
|
# a given key. This value is used to provide simple optimistic
|
@@ -305,10 +294,7 @@ module Libcouchbase
|
|
305
294
|
# @example Store the key which will be expired in 2 seconds using absolute TTL.
|
306
295
|
# c.replace(:foo, :bar, expire_at: Time.now.to_i + 2)
|
307
296
|
#
|
308
|
-
# @example
|
309
|
-
# c.replace("foo", {"bar" => "baz"}, format: :document)
|
310
|
-
#
|
311
|
-
# @example Set application specific flags (note that it will be OR-ed with format flags)
|
297
|
+
# @example Set application specific flags
|
312
298
|
# c.replace("foo", "bar", flags: 0x1000)
|
313
299
|
#
|
314
300
|
# @example Ensure that the key will be persisted at least on the one node
|
@@ -320,12 +306,6 @@ module Libcouchbase
|
|
320
306
|
|
321
307
|
# Append this object to the existing object
|
322
308
|
#
|
323
|
-
# @note This operation is kind of data-aware from server point of view.
|
324
|
-
# This mean that the server treats value as binary stream and just
|
325
|
-
# perform concatenation, therefore it won't work with +:marshal+ and
|
326
|
-
# +:document+ formats, because of lack of knowledge how to merge values
|
327
|
-
# in these formats.
|
328
|
-
#
|
329
309
|
# @param key [String, Symbol] Key used to reference the value.
|
330
310
|
# @param value [Object] Value to be appended
|
331
311
|
# @param options [Hash] Options for operation.
|
@@ -348,12 +328,12 @@ module Libcouchbase
|
|
348
328
|
# @raise [Libcouchbase::Error::KeyNotFound] if the key doesn't exists
|
349
329
|
#
|
350
330
|
# @example Simple append
|
351
|
-
# c.set(:foo, "aaa"
|
331
|
+
# c.set(:foo, "aaa")
|
352
332
|
# c.append(:foo, "bbb")
|
353
333
|
# c.get("foo") #=> "aaabbb"
|
354
334
|
#
|
355
335
|
# @example Using optimistic locking. The operation will fail on CAS mismatch
|
356
|
-
# resp = c.set("foo", "aaa"
|
336
|
+
# resp = c.set("foo", "aaa")
|
357
337
|
# c.append("foo", "bbb", cas: resp.cas)
|
358
338
|
#
|
359
339
|
# @example Ensure that the key will be persisted at least on the one node
|
@@ -365,12 +345,6 @@ module Libcouchbase
|
|
365
345
|
|
366
346
|
# Prepend this object to the existing object
|
367
347
|
#
|
368
|
-
# @note This operation is kind of data-aware from server point of view.
|
369
|
-
# This mean that the server treats value as binary stream and just
|
370
|
-
# perform concatenation, therefore it won't work with +:marshal+ and
|
371
|
-
# +:document+ formats, because of lack of knowledge how to merge values
|
372
|
-
# in these formats.
|
373
|
-
#
|
374
348
|
# @param key [String, Symbol] Key used to reference the value.
|
375
349
|
# @param value [Object] Value to be appended
|
376
350
|
# @param options [Hash] Options for operation.
|
@@ -393,12 +367,12 @@ module Libcouchbase
|
|
393
367
|
# @raise [Libcouchbase::Error::KeyNotFound] if the key doesn't exists
|
394
368
|
#
|
395
369
|
# @example Simple prepend
|
396
|
-
# c.set(:foo, "aaa"
|
370
|
+
# c.set(:foo, "aaa")
|
397
371
|
# c.prepend(:foo, "bbb")
|
398
372
|
# c.get("foo") #=> "bbbaaa"
|
399
373
|
#
|
400
374
|
# @example Using optimistic locking. The operation will fail on CAS mismatch
|
401
|
-
# resp = c.set("foo", "aaa"
|
375
|
+
# resp = c.set("foo", "aaa")
|
402
376
|
# c.prepend("foo", "bbb", cas: resp.cas)
|
403
377
|
#
|
404
378
|
# @example Ensure that the key will be persisted at least on the one node
|
@@ -506,7 +480,7 @@ module Libcouchbase
|
|
506
480
|
# c.delete("foo", quiet: false) #=> will raise Libcouchbase::Error::KeyNotFound
|
507
481
|
#
|
508
482
|
# @example Delete the key with version check
|
509
|
-
# res = c.set("foo", "bar") #=> #<struct Libcouchbase::Response callback=:callback_set, key="foo", cas=1975457268957184, value="bar", metadata={:
|
483
|
+
# res = c.set("foo", "bar") #=> #<struct Libcouchbase::Response callback=:callback_set, key="foo", cas=1975457268957184, value="bar", metadata={:flags=>0}>
|
510
484
|
# c.delete("foo", cas: 123456) #=> will raise Libcouchbase::Error::KeyExists
|
511
485
|
# c.delete("foo", cas: res.cas) #=> true
|
512
486
|
def delete(key, async: false, quiet: true, **opts)
|
@@ -259,19 +259,8 @@ module Libcouchbase
|
|
259
259
|
|
260
260
|
NonJsonValue = [:append, :prepend].freeze
|
261
261
|
|
262
|
-
# These are client specific
|
263
|
-
FormatFlags = {
|
264
|
-
document: 0,
|
265
|
-
marshal: 1,
|
266
|
-
plain: 2
|
267
|
-
}
|
268
|
-
SupportedFormats = FormatFlags.keys.freeze
|
269
|
-
FormatFlags.merge!(FormatFlags.invert)
|
270
|
-
FormatFlags.freeze
|
271
|
-
|
272
262
|
# http://docs.couchbase.com/sdk-api/couchbase-c-client-2.6.2/group__lcb-store.html
|
273
263
|
# http://docs.couchbase.com/sdk-api/couchbase-c-client-2.6.2/group__lcb-durability.html
|
274
|
-
# NOTE:: first 2 bits of the flags are reserved for document format
|
275
264
|
def store(key, value,
|
276
265
|
defer: nil,
|
277
266
|
operation: :set,
|
@@ -280,12 +269,10 @@ module Libcouchbase
|
|
280
269
|
ttl: nil,
|
281
270
|
persist_to: 0,
|
282
271
|
replicate_to: 0,
|
283
|
-
format: :document,
|
284
272
|
cas: nil,
|
285
273
|
flags: 0,
|
286
274
|
**opts)
|
287
275
|
raise 'not connected' unless @handle
|
288
|
-
raise 'format not supported' unless SupportedFormats.include?(:document)
|
289
276
|
defer ||= @reactor.defer
|
290
277
|
|
291
278
|
# Check if this should be a durable operation
|
@@ -298,26 +285,16 @@ module Libcouchbase
|
|
298
285
|
cmd = Ext::CMDSTORE.new
|
299
286
|
end
|
300
287
|
cmd[:operation] = operation
|
288
|
+
cmd[:flags] = flags
|
301
289
|
|
302
|
-
|
303
|
-
|
304
|
-
format = :plain
|
305
|
-
else
|
306
|
-
# Preserve any application specific flags and set the format flags
|
307
|
-
flag_mask = flags & 3
|
308
|
-
flags = flags ^ flag_mask
|
309
|
-
cmd[:flags] = flags | FormatFlags[format]
|
310
|
-
end
|
311
|
-
|
312
|
-
# Move the data into the correct format for storage
|
313
|
-
if format == :marshal
|
314
|
-
str_value = Marshal.dump(value)
|
315
|
-
elsif format == :plain
|
316
|
-
# Use coercion as it was intended
|
317
|
-
str_value = value.respond_to?(:to_str) ? value.to_str : value.to_s
|
290
|
+
if value.is_a?(String)
|
291
|
+
str_value = value
|
318
292
|
else
|
319
|
-
|
320
|
-
|
293
|
+
str_value = begin
|
294
|
+
JSON.generate([value])[1..-2]
|
295
|
+
rescue
|
296
|
+
value.respond_to?(:to_str) ? value.to_str : value.to_s
|
297
|
+
end
|
321
298
|
end
|
322
299
|
|
323
300
|
req = Request.new(cmd, defer)
|
@@ -339,13 +316,12 @@ module Libcouchbase
|
|
339
316
|
end
|
340
317
|
|
341
318
|
# http://docs.couchbase.com/sdk-api/couchbase-c-client-2.6.2/group__lcb-get.html
|
342
|
-
def get(key, defer: nil, lock: false, cas: nil,
|
319
|
+
def get(key, defer: nil, lock: false, cas: nil, **opts)
|
343
320
|
raise 'not connected' unless @handle
|
344
321
|
defer ||= @reactor.defer
|
345
322
|
|
346
323
|
cmd = Ext::CMDGET.new
|
347
324
|
req = Request.new(cmd, defer)
|
348
|
-
req.value = format
|
349
325
|
key = cmd_set_key(req, cmd, key)
|
350
326
|
cmd[:cas] = cas if cas
|
351
327
|
|
@@ -584,24 +560,13 @@ module Libcouchbase
|
|
584
560
|
QueryN1QL.new(self, @reactor, n1ql, **opts)
|
585
561
|
end
|
586
562
|
|
587
|
-
def parse_document(raw_string
|
588
|
-
flag_mask = flags & 3
|
589
|
-
format = hint || FormatFlags[flag_mask] # Defaults to document
|
563
|
+
def parse_document(raw_string)
|
590
564
|
val = begin
|
591
|
-
|
592
|
-
|
593
|
-
Marshal.load(raw_string)
|
594
|
-
when :document
|
595
|
-
JSON.parse("[#{raw_string}]", DECODE_OPTIONS)[0]
|
596
|
-
else
|
597
|
-
format = :plain
|
598
|
-
raw_string
|
599
|
-
end
|
600
|
-
rescue => e
|
601
|
-
format = :plain
|
565
|
+
JSON.parse("[#{raw_string}]", DECODE_OPTIONS)[0]
|
566
|
+
rescue
|
602
567
|
raw_string
|
603
568
|
end
|
604
|
-
|
569
|
+
val
|
605
570
|
end
|
606
571
|
|
607
572
|
|
@@ -689,8 +654,8 @@ module Libcouchbase
|
|
689
654
|
resp = Ext::RESPGET.new response
|
690
655
|
resp_callback_common(resp, :callback_get) do |req, cb|
|
691
656
|
raw_string = resp[:value].read_string(resp[:nvalue])
|
692
|
-
val
|
693
|
-
Response.new(cb, req.key, resp[:cas], val, {
|
657
|
+
val = parse_document(raw_string)
|
658
|
+
Response.new(cb, req.key, resp[:cas], val, {flags: resp[:itmflags]})
|
694
659
|
end
|
695
660
|
end
|
696
661
|
|
@@ -96,7 +96,7 @@ module Libcouchbase
|
|
96
96
|
if @include_docs && row[:docresp]
|
97
97
|
doc = row[:docresp]
|
98
98
|
raw_string = doc[:value].null? ? '' : doc[:value].read_string(doc[:nvalue])
|
99
|
-
resp.value
|
99
|
+
resp.value = @connection.parse_document(raw_string)
|
100
100
|
meta[:flags] = doc[:itmflags]
|
101
101
|
end
|
102
102
|
|
data/lib/libcouchbase/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libcouchbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen von Takach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|