SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
Getting Started with
    Couchbase Ruby
              Sergey Avseyev
       sergey@couchbase.com
Couchbase Server
What Is Couchbase Server




 • NoSQL database solution
 • No fixed schema
 • Automatic key sharding
 • Automatic replication
 • Low latency optimized
 • No multi-operation transaction support
Who Uses Couchbase Server: Heroku




 • Leading cloud service (PAAS) provider
 • Over 1,500,000 hosted applications
 • Couchbase Server serving over 11,800 Heroku customers
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
Current Version: 1.1.2
Installation



Install stable version of libcouchbase-dev with dependencies using
instructions 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
Connect to the Cluster



Pass connection parameters explicitly

  conn = Couchbase.connect(:bucket => ’test’)


Use thread-local connection instance

  Couchbase.connection_options = :bucket => ’test’
  conn = Couchbase.bucket
Simple CRUD
Write 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”)
Optimistic Locks


All mutators accepts CAS value (some kind of version or checksum of the
key)

    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
Expiration


Write 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)
Miscellaneous

Multi 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”)
Next Version: 1.2.0.dp5
Installation



Install next version of libcouchbase-dev with dependencies using
instructions 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
Map/Reduce Analysis
Define design document containing single map function (using admin
panel or Bucket#save_design_doc):

    {
        ”_id”: ”_design/users”,
        ”views”: {
          ”all_by_email”: {
            ”map”: ”function(doc) {
                      if (doc.type == ”User”)
                        emit(doc.email, null);
                    }”
          },
        }
    }
Executing views


Pick 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
Pessimistic Locks




    value = conn.get(”key”, :lock => 5.seconds)


All subsequent mutators are forced to use corresponding CAS value or fail
Rack Session Storage




   # config.ru
   require ’rack/session/couchbase’
   use Rack::Session::Couchbase,
       :expire_after => 5.minutes,
       :couchbase => {:bucket => ”sessions”}
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”}
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
Even More :)
ODM (Object Document Model) for Rails


https://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
Couchbase for EventMachine (experimental)




https://github.com/couchbaselabs/couchbase-ruby-client-em

   $ gem install em-couchbase
Thanks
Questions?
Find these slides at:
github.com/avsej/getting-started-with-couchbase-ruby

Contenu connexe

Tendances

Ansible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaAnsible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaTetiana Saputo
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationJohn Lynch
 
Autoscaling with hashi_corp_nomad
Autoscaling with hashi_corp_nomadAutoscaling with hashi_corp_nomad
Autoscaling with hashi_corp_nomadBram Vogelaar
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupGreg DeKoenigsberg
 
AnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricksjimi-c
 
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorAutomating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorDigicomp Academy AG
 
Data integration with embulk
Data integration with embulkData integration with embulk
Data integration with embulkTeguh Nugraha
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer Hiroshi SHIBATA
 
Building Distributed System with Celery on Docker Swarm
Building Distributed System with Celery on Docker SwarmBuilding Distributed System with Celery on Docker Swarm
Building Distributed System with Celery on Docker SwarmWei Lin
 
V2 and beyond
V2 and beyondV2 and beyond
V2 and beyondjimi-c
 
Docker & CoreOS at Utah Gophers
Docker & CoreOS at Utah GophersDocker & CoreOS at Utah Gophers
Docker & CoreOS at Utah GophersJosh Braegger
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and ContainersRodolfo Carvalho
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
 
Developers’ mDay 2019. - Rastko Vasiljević, SuperAdmins – Infrastructure as c...
Developers’ mDay 2019. - Rastko Vasiljević, SuperAdmins – Infrastructure as c...Developers’ mDay 2019. - Rastko Vasiljević, SuperAdmins – Infrastructure as c...
Developers’ mDay 2019. - Rastko Vasiljević, SuperAdmins – Infrastructure as c...mCloud
 
Czym jest webpack i dlaczego chcesz go używać?
Czym jest webpack i dlaczego chcesz go używać?Czym jest webpack i dlaczego chcesz go używać?
Czym jest webpack i dlaczego chcesz go używać?Marcin Gajda
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleCoreStack
 
PowerShell User Group Hamburg - PowerCLI
PowerShell User Group Hamburg - PowerCLIPowerShell User Group Hamburg - PowerCLI
PowerShell User Group Hamburg - PowerCLIMarkus Kraus
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkMichael Peacock
 

Tendances (20)

Ansible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaAnsible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy Mykhailiuta
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Autoscaling with hashi_corp_nomad
Autoscaling with hashi_corp_nomadAutoscaling with hashi_corp_nomad
Autoscaling with hashi_corp_nomad
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetup
 
AnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricks
 
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorAutomating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
 
Data integration with embulk
Data integration with embulkData integration with embulk
Data integration with embulk
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer
 
Building Distributed System with Celery on Docker Swarm
Building Distributed System with Celery on Docker SwarmBuilding Distributed System with Celery on Docker Swarm
Building Distributed System with Celery on Docker Swarm
 
V2 and beyond
V2 and beyondV2 and beyond
V2 and beyond
 
Docker & CoreOS at Utah Gophers
Docker & CoreOS at Utah GophersDocker & CoreOS at Utah Gophers
Docker & CoreOS at Utah Gophers
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 
Developers’ mDay 2019. - Rastko Vasiljević, SuperAdmins – Infrastructure as c...
Developers’ mDay 2019. - Rastko Vasiljević, SuperAdmins – Infrastructure as c...Developers’ mDay 2019. - Rastko Vasiljević, SuperAdmins – Infrastructure as c...
Developers’ mDay 2019. - Rastko Vasiljević, SuperAdmins – Infrastructure as c...
 
Czym jest webpack i dlaczego chcesz go używać?
Czym jest webpack i dlaczego chcesz go używać?Czym jest webpack i dlaczego chcesz go używać?
Czym jest webpack i dlaczego chcesz go używać?
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
PowerShell User Group Hamburg - PowerCLI
PowerShell User Group Hamburg - PowerCLIPowerShell User Group Hamburg - PowerCLI
PowerShell User Group Hamburg - PowerCLI
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech Talk
 
Vidoop CouchDB Talk
Vidoop CouchDB TalkVidoop CouchDB Talk
Vidoop CouchDB Talk
 

En vedette

2015-12-05 Данил Никифоров - NoSQL для мобайла с синхронизацией данных
2015-12-05 Данил Никифоров - NoSQL для мобайла с синхронизацией данных2015-12-05 Данил Никифоров - NoSQL для мобайла с синхронизацией данных
2015-12-05 Данил Никифоров - NoSQL для мобайла с синхронизацией данныхHappyDev
 
Web весна 2012 лекция 6
Web весна 2012 лекция 6Web весна 2012 лекция 6
Web весна 2012 лекция 6Technopark
 
Опыт использования NoSQL-хранилищ (Андрей Новиков)
Опыт использования NoSQL-хранилищ (Андрей Новиков)Опыт использования NoSQL-хранилищ (Андрей Новиков)
Опыт использования NoSQL-хранилищ (Андрей Новиков)Olga Lavrentieva
 
Спасение 6 млн файлов в условиях полного хецнера (Даниил Подольский, Дмитрий ...
Спасение 6 млн файлов в условиях полного хецнера (Даниил Подольский, Дмитрий ...Спасение 6 млн файлов в условиях полного хецнера (Даниил Подольский, Дмитрий ...
Спасение 6 млн файлов в условиях полного хецнера (Даниил Подольский, Дмитрий ...Ontico
 
NoSQL - World IT Planet, Saint Petersburg 2015
NoSQL - World IT Planet, Saint Petersburg 2015NoSQL - World IT Planet, Saint Petersburg 2015
NoSQL - World IT Planet, Saint Petersburg 2015Shamim bhuiyan
 
Как устроен NoSQL, Андрей Аксенов (Sphinx)
Как устроен NoSQL, Андрей Аксенов (Sphinx)Как устроен NoSQL, Андрей Аксенов (Sphinx)
Как устроен NoSQL, Андрей Аксенов (Sphinx)Ontico
 
Oracle NoSQL Database
Oracle NoSQL DatabaseOracle NoSQL Database
Oracle NoSQL DatabaseAndrey Akulov
 
Apache Cassandra. Ещё одно NoSQL хранилище (Владимир Климонтович)
Apache Cassandra. Ещё одно NoSQL хранилище (Владимир Климонтович)Apache Cassandra. Ещё одно NoSQL хранилище (Владимир Климонтович)
Apache Cassandra. Ещё одно NoSQL хранилище (Владимир Климонтович)Ontico
 
NoSQL и Zend Framework (Ростислав Михайлив)
NoSQL и Zend Framework (Ростислав Михайлив)NoSQL и Zend Framework (Ростислав Михайлив)
NoSQL и Zend Framework (Ростислав Михайлив)zfconfua
 
За гранью NoSQL: NewSQL на Cassandra
За гранью NoSQL: NewSQL на CassandraЗа гранью NoSQL: NewSQL на Cassandra
За гранью NoSQL: NewSQL на Cassandraodnoklassniki.ru
 
СУБД 2013 Лекция №10 "Нереляционное решение в области баз данных — NoSQL"
СУБД 2013 Лекция №10 "Нереляционное решение в области баз данных — NoSQL"СУБД 2013 Лекция №10 "Нереляционное решение в области баз данных — NoSQL"
СУБД 2013 Лекция №10 "Нереляционное решение в области баз данных — NoSQL"Technopark
 
NoSQL - коротко о главном / Сергей Туленцев (TextMaster)
NoSQL - коротко о главном / Сергей Туленцев (TextMaster)NoSQL - коротко о главном / Сергей Туленцев (TextMaster)
NoSQL - коротко о главном / Сергей Туленцев (TextMaster)Ontico
 
NoSQL - взрыв возможностей
NoSQL - взрыв возможностейNoSQL - взрыв возможностей
NoSQL - взрыв возможностейAleksey Solntsev
 
ClickHouse: очень быстро и очень удобно / Виктор Тарнавский, Алексей Миловидо...
ClickHouse: очень быстро и очень удобно / Виктор Тарнавский, Алексей Миловидо...ClickHouse: очень быстро и очень удобно / Виктор Тарнавский, Алексей Миловидо...
ClickHouse: очень быстро и очень удобно / Виктор Тарнавский, Алексей Миловидо...Ontico
 
NoNoSQL = Not Only NoSQL, HappyDev'13
NoNoSQL = Not Only NoSQL, HappyDev'13NoNoSQL = Not Only NoSQL, HappyDev'13
NoNoSQL = Not Only NoSQL, HappyDev'13chaltaj
 

En vedette (15)

2015-12-05 Данил Никифоров - NoSQL для мобайла с синхронизацией данных
2015-12-05 Данил Никифоров - NoSQL для мобайла с синхронизацией данных2015-12-05 Данил Никифоров - NoSQL для мобайла с синхронизацией данных
2015-12-05 Данил Никифоров - NoSQL для мобайла с синхронизацией данных
 
Web весна 2012 лекция 6
Web весна 2012 лекция 6Web весна 2012 лекция 6
Web весна 2012 лекция 6
 
Опыт использования NoSQL-хранилищ (Андрей Новиков)
Опыт использования NoSQL-хранилищ (Андрей Новиков)Опыт использования NoSQL-хранилищ (Андрей Новиков)
Опыт использования NoSQL-хранилищ (Андрей Новиков)
 
Спасение 6 млн файлов в условиях полного хецнера (Даниил Подольский, Дмитрий ...
Спасение 6 млн файлов в условиях полного хецнера (Даниил Подольский, Дмитрий ...Спасение 6 млн файлов в условиях полного хецнера (Даниил Подольский, Дмитрий ...
Спасение 6 млн файлов в условиях полного хецнера (Даниил Подольский, Дмитрий ...
 
NoSQL - World IT Planet, Saint Petersburg 2015
NoSQL - World IT Planet, Saint Petersburg 2015NoSQL - World IT Planet, Saint Petersburg 2015
NoSQL - World IT Planet, Saint Petersburg 2015
 
Как устроен NoSQL, Андрей Аксенов (Sphinx)
Как устроен NoSQL, Андрей Аксенов (Sphinx)Как устроен NoSQL, Андрей Аксенов (Sphinx)
Как устроен NoSQL, Андрей Аксенов (Sphinx)
 
Oracle NoSQL Database
Oracle NoSQL DatabaseOracle NoSQL Database
Oracle NoSQL Database
 
Apache Cassandra. Ещё одно NoSQL хранилище (Владимир Климонтович)
Apache Cassandra. Ещё одно NoSQL хранилище (Владимир Климонтович)Apache Cassandra. Ещё одно NoSQL хранилище (Владимир Климонтович)
Apache Cassandra. Ещё одно NoSQL хранилище (Владимир Климонтович)
 
NoSQL и Zend Framework (Ростислав Михайлив)
NoSQL и Zend Framework (Ростислав Михайлив)NoSQL и Zend Framework (Ростислав Михайлив)
NoSQL и Zend Framework (Ростислав Михайлив)
 
За гранью NoSQL: NewSQL на Cassandra
За гранью NoSQL: NewSQL на CassandraЗа гранью NoSQL: NewSQL на Cassandra
За гранью NoSQL: NewSQL на Cassandra
 
СУБД 2013 Лекция №10 "Нереляционное решение в области баз данных — NoSQL"
СУБД 2013 Лекция №10 "Нереляционное решение в области баз данных — NoSQL"СУБД 2013 Лекция №10 "Нереляционное решение в области баз данных — NoSQL"
СУБД 2013 Лекция №10 "Нереляционное решение в области баз данных — NoSQL"
 
NoSQL - коротко о главном / Сергей Туленцев (TextMaster)
NoSQL - коротко о главном / Сергей Туленцев (TextMaster)NoSQL - коротко о главном / Сергей Туленцев (TextMaster)
NoSQL - коротко о главном / Сергей Туленцев (TextMaster)
 
NoSQL - взрыв возможностей
NoSQL - взрыв возможностейNoSQL - взрыв возможностей
NoSQL - взрыв возможностей
 
ClickHouse: очень быстро и очень удобно / Виктор Тарнавский, Алексей Миловидо...
ClickHouse: очень быстро и очень удобно / Виктор Тарнавский, Алексей Миловидо...ClickHouse: очень быстро и очень удобно / Виктор Тарнавский, Алексей Миловидо...
ClickHouse: очень быстро и очень удобно / Виктор Тарнавский, Алексей Миловидо...
 
NoNoSQL = Not Only NoSQL, HappyDev'13
NoNoSQL = Not Only NoSQL, HappyDev'13NoNoSQL = Not Only NoSQL, HappyDev'13
NoNoSQL = Not Only NoSQL, HappyDev'13
 

Similaire à Getting Started with Couchbase Ruby

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Cutting through the fog of cloud
Cutting through the fog of cloudCutting through the fog of cloud
Cutting through the fog of cloudKyle Rames
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the CloudWesley Beary
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)Wesley Beary
 
Packer, where DevOps begins
Packer, where DevOps beginsPacker, where DevOps begins
Packer, where DevOps beginsJeff Hung
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Carlos Sanchez
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012Carlos Sanchez
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) RoundupWayne Carter
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardSV Ruby on Rails Meetup
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.Mike Brevoort
 
Puppetpreso
PuppetpresoPuppetpreso
Puppetpresoke4qqq
 
Puppet and Apache CloudStack
Puppet and Apache CloudStackPuppet and Apache CloudStack
Puppet and Apache CloudStackPuppet
 
Infrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStackInfrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStackke4qqq
 
Puppet and CloudStack
Puppet and CloudStackPuppet and CloudStack
Puppet and CloudStackke4qqq
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Simon McCartney
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
AWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaAWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaManish Pandit
 

Similaire à Getting Started with Couchbase Ruby (20)

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Cutting through the fog of cloud
Cutting through the fog of cloudCutting through the fog of cloud
Cutting through the fog of cloud
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
Packer, where DevOps begins
Packer, where DevOps beginsPacker, where DevOps begins
Packer, where DevOps begins
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) Roundup
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
Puppetpreso
PuppetpresoPuppetpreso
Puppetpreso
 
Puppet and Apache CloudStack
Puppet and Apache CloudStackPuppet and Apache CloudStack
Puppet and Apache CloudStack
 
Infrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStackInfrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStack
 
Puppet and CloudStack
Puppet and CloudStackPuppet and CloudStack
Puppet and CloudStack
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
AWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaAWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and Java
 
Igor Davydenko
Igor DavydenkoIgor Davydenko
Igor Davydenko
 

Dernier

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Dernier (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Getting Started with Couchbase Ruby

  • 1. Getting Started with Couchbase Ruby Sergey Avseyev sergey@couchbase.com
  • 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
  • 7. Installation Install stable version of libcouchbase-dev with dependencies using instructions 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 Cluster Pass connection parameters explicitly conn = Couchbase.connect(:bucket => ’test’) Use thread-local connection instance Couchbase.connection_options = :bucket => ’test’ conn = Couchbase.bucket
  • 9. Simple CRUD Write 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 Locks All mutators accepts CAS value (some kind of version or checksum of the key) 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. Expiration Write 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. Miscellaneous Multi 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”)
  • 14. Installation Install next version of libcouchbase-dev with dependencies using instructions 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 Analysis Define design document containing single map function (using admin panel 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 views Pick 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
  • 22. ODM (Object Document Model) for Rails https://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
  • 25. Find these slides at: github.com/avsej/getting-started-with-couchbase-ruby