SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

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