Getting Started with Couchbase Ruby
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Getting Started with Couchbase Ruby

on

  • 2,679 views

 

Statistics

Views

Total Views
2,679
Views on SlideShare
2,642
Embed Views
37

Actions

Likes
1
Downloads
11
Comments
0

3 Embeds 37

http://embedslides.blogspot.in 35
http://embedslides.blogspot.com 1
https://embedslides.blogspot.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Getting Started with Couchbase Ruby Presentation Transcript

  • 1. Getting Started with Couchbase Ruby Sergey Avseyev sergey@couchbase.com
  • 2. Couchbase Server
  • 3. What Is Couchbase Server • NoSQL database solution • No fixed schema • Automatic key sharding • Automatic replication • Low latency optimized • No multi-operation transaction support
  • 4. Who Uses Couchbase Server: Heroku • Leading cloud service (PAAS) provider • Over 1,500,000 hosted applications • Couchbase Server serving over 11,800 Heroku customers
  • 5. Who Uses Couchbase Server: Zynga • Social game leader — FarmVille, Mafia Wars, Empires and Allies, Café World, FishVille • Over 230 million monthly users • Couchbase Server is the primary database behind key Zynga properties
  • 6. Current Version: 1.1.2
  • 7. InstallationInstall stable version of libcouchbase-dev with dependencies usinginstructions at http://www.couchbase.com/develop/c/current $ gem install couchbase Fetching: couchbase-1.1.2.gem (100%) Building native extensions. This could take a while... Successfully installed couchbase-1.1.2 1 gems installed
  • 8. Connect to the ClusterPass connection parameters explicitly conn = Couchbase.connect(:bucket => ’test’)Use thread-local connection instance Couchbase.connection_options = :bucket => ’test’ conn = Couchbase.bucket
  • 9. Simple CRUDWrite key or fail it it is exists already cas = conn.add(”key”, ”value”)Write key unconditionally cas = conn.set(”key”, ”value”)Write key only if it is exists cas = conn.replace(”key”, ”value”) value = conn.get(”key”)
  • 10. Optimistic LocksAll mutators accepts CAS value (some kind of version or checksum of thekey) value, flags, cas = conn.get(”key”, ”value”, :extended => true)Setting with wrong CAS value will raise Couchbase::Error::KeyExists conn.set(”key”, ”newvalue”, :cas => 1234) #=> Couchbase::Error::KeyExists: failed to store value
  • 11. ExpirationWrite key and set expiration conn.set(”key”, ”value”, :ttl => 1.minute)Read key and set expiration conn.get(”key”, :ttl => 1.minute)Only update expiration conn.touch(”key”, :ttl => 1.minute)
  • 12. MiscellaneousMulti get foo, bar = conn.get(”foo”, ”bar”)Multi touch conn.touch(”foo” => 30.seconds, ”bar” => 10.minutes)Increment/Decrement conn.incr(”counter”) conn.decr(”counter”)
  • 13. Next Version: 1.2.0.dp5
  • 14. InstallationInstall next version of libcouchbase-dev with dependencies usinginstructions at http://www.couchbase.com/develop/c/next $ gem install couchbase --pre Fetching: couchbase-1.2.0.dp5.gem (100%) Building native extensions. This could take a while... Successfully installed couchbase-1.2.0.dp5 1 gems installed
  • 15. Map/Reduce AnalysisDefine design document containing single map function (using adminpanel or Bucket#save_design_doc): { ”_id”: ”_design/users”, ”views”: { ”all_by_email”: { ”map”: ”function(doc) { if (doc.type == ”User”) emit(doc.email, null); }” }, } }
  • 16. Executing viewsPick up design document: ddoc = conn.design_docs[”users”]Iterate over view results ddoc.all_by_email(:include_docs => true).each do |doc| puts doc.key puts doc.doc.inspect end
  • 17. Pessimistic Locks value = conn.get(”key”, :lock => 5.seconds)All subsequent mutators are forced to use corresponding CAS value or fail
  • 18. Rack Session Storage # config.ru require ’rack/session/couchbase’ use Rack::Session::Couchbase, :expire_after => 5.minutes, :couchbase => {:bucket => ”sessions”}
  • 19. Rails Session Storage # config/initializers/session_store.rb require ’action_dispatch/middleware/session/couchbase_store’ Name::Application.config.session_store :couchbase_store, :expire_after => 5.minutes, :couchbase => {:bucket => ”sessions”}
  • 20. Rails Cache Storage # config/application.rb cache_options = { :bucket => ’protected’, :username => ’protected’, :password => ’secret’, :expires_in => 2.hours } config.cache_store = :couchbase_store, cache_options
  • 21. Even More :)
  • 22. ODM (Object Document Model) for Railshttps://github.com/couchbaselabs/ruby-couchbase-model $ gem install couchbase-model class Post < Couchbase::Model attribute :title attribute :body attribute :created_at, :default => lambda { Time.now } view :by_created_at end
  • 23. Couchbase for EventMachine (experimental)https://github.com/couchbaselabs/couchbase-ruby-client-em $ gem install em-couchbase
  • 24. ThanksQuestions?
  • 25. Find these slides at:github.com/avsej/getting-started-with-couchbase-ruby