-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep2.rb
37 lines (22 loc) · 1.11 KB
/
step2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Couchbase Ruby SDK quick-start part 2
require 'couchbase'
# Connect to the database
db = Couchbase.connect(:hostname => "localhost", :key_prefix => "swag_")
# Read in a document
document, flags, cas = db.get("PENCBLOGO", :extended => true)
puts "Item: #{document["Description"]}. Quantity: #{document["Quantity"]}.\n"
# Change the document
document["Description"] = "Red Couchbase pen with logo"
db.set("PENCBLOGO", document, :cas => cas, :flags => flags)
# Read it again
document, flags, cas2 = db.get("PENCBLOGO", :extended => true)
puts "Item: #{document["Description"]}. Quantity: #{document["Quantity"]}.\n"
# Change the document again, using the old CAS. This will fail.
document["Description"] = "Red ball-point pen with Couchbase logo"
db.set("PENCBLOGO", document, :cas => cas2, :flags => flags)
# Try again using the second CAS value
document["Description"] = "Red Couchbase pen with logo"
db.set("PENCBLOGO", document, :cas => cas2, :flags => flags)
# Read it again
document, flags, cas2 = db.get("PENCBLOGO", :extended => true)
puts "Item: #{document["Description"]}. Quantity: #{document["Quantity"]}.\n"