CouchConf_Developer Lab
Transcript of CouchConf_Developer Lab
![Page 1: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/1.jpg)
Friday, December 7, 12
![Page 2: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/2.jpg)
Technical Evangelist / Developer Advocate
twi7er: @scalabl3 @codevoyeur
email: [email protected] [email protected]
Jasdeep Jaitla / John Zablocki
Develop with Couchbase
Friday, December 7, 12
![Page 3: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/3.jpg)
Technical Evangelist / Developer Advocate
twi7er: @scalabl3 @codevoyeur
email: [email protected] [email protected]
Jasdeep Jaitla / John Zablocki
Develop with Couchbase
Friday, December 7, 12
![Page 4: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/4.jpg)
Friday, December 7, 12
![Page 5: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/5.jpg)
COUCHBASE SERVER
Friday, December 7, 12
![Page 6: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/6.jpg)
Install Couchbase Server’s Latest Build
Download the Latest Build of Couchbase Server
1. h7p://www.couchbase.com/downloads-‐all2. In the second secRon down the page... Select the most recent build of Couchbase (Build 1954) in the dropdown
3. Download for your OS, then,4. Install based on your OS, instrucRons are on the leZ under each logo
If you are Upgrading your installa=on from a previous version/build
1. Download Couchbase for the OS, and we can help you upgrade at the lab2. If you are on MacOSX, there are Rps/instrucRons at
h7p://CouchbaseOnRails.com/install
Friday, December 7, 12
![Page 7: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/7.jpg)
(1) Setup Couchbase
Browse to Couchbase Admin Panelh7p://localhost:8091/
(if you didn’t install on local machine, subsRtute IP address for localhost)
Friday, December 7, 12
![Page 8: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/8.jpg)
(2) Setup Couchbase -‐ RAM Quota
Even on laptops, it’s typical to set this fairly high, it won’t all get used unless you have that much data in memory... Recommended to use at least 1024 MB!
RAM Quota is the Memory Cap for each Couchbase Server in the Cluster
FYI: Changing this requires using command line and couchbase restart, it’s not done in interface
PorRons of this quota are allocated to each Bucket (Database) that you setup, you are seeng the maximum memory to allocate in this step.
Friday, December 7, 12
![Page 9: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/9.jpg)
(2) Setup Couchbase -‐ RAM Quota
Even on laptops, it’s typical to set this fairly high, it won’t all get used unless you have that much data in memory... Recommended to use at least 1024 MB!
RAM Quota is the Memory Cap for each Couchbase Server in the Cluster
FYI: Changing this requires using command line and couchbase restart, it’s not done in interface
PorRons of this quota are allocated to each Bucket (Database) that you setup, you are seeng the maximum memory to allocate in this step.
Friday, December 7, 12
![Page 10: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/10.jpg)
(3) Setup Couchbase -‐ Samples
This can also be done at a later Rme aZer things are setup...
Op=onally Setup some Sample Data with Example Views (Map/Reduce Indexes)
Friday, December 7, 12
![Page 11: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/11.jpg)
(4) Setup Couchbase -‐ Default Bucket
You’ll likely setup more than one Bucket while playing & tesRng, so don’t use all your Quota here, 300MB is a good size, this is easily changed later in Web Admin.
Setup RAM and SeKngs for Default Bucket (percentage of server RAM Quota in first step)
Friday, December 7, 12
![Page 12: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/12.jpg)
(4) Setup Couchbase -‐ Default Bucket
You’ll likely setup more than one Bucket while playing & tesRng, so don’t use all your Quota here, 300MB is a good size, this is easily changed later in Web Admin.
Setup RAM and SeKngs for Default Bucket (percentage of server RAM Quota in first step)
Friday, December 7, 12
![Page 13: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/13.jpg)
(4) Setup Couchbase -‐ Default Bucket
You’ll likely setup more than one Bucket while playing & tesRng, so don’t use all your Quota here, 300MB is a good size, this is easily changed later in Web Admin.
Setup RAM and SeKngs for Default Bucket (percentage of server RAM Quota in first step)
Since you have a single node cluster locally, there won’t be any replicas even if enabled
Allows you to delete all data in Bucket in one command, good for
testing
Friday, December 7, 12
![Page 14: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/14.jpg)
(5) Setup Couchbase -‐ NoRficaRonsIf you want no=fica=ons of soNware updates,
check this box and put in your info
Friday, December 7, 12
![Page 15: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/15.jpg)
(6) Setup Couchbase -‐ Admin U/PSet your Username/Password to the Web Admin Console
Friday, December 7, 12
![Page 16: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/16.jpg)
Congrats!You’re now level 2.
Friday, December 7, 12
![Page 17: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/17.jpg)
Web Admin Quick Tour!
Friday, December 7, 12
![Page 18: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/18.jpg)
Web Admin Quick Tour!Overview of ClusterRAM, Disk, Ops, etc.
Friday, December 7, 12
![Page 19: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/19.jpg)
Web Admin Quick Tour!
List of Cluster Nodes & Stats
If you Enable Replication but have too few nodes, you’ll see
this warning
Friday, December 7, 12
![Page 20: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/20.jpg)
Web Admin Quick Tour!
List of Cluster Nodes & Stats
If you Enable Replication but have too few nodes, you’ll see
this warning
List of Cluster Nodes & Stats
Friday, December 7, 12
![Page 21: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/21.jpg)
Web Admin Quick Tour!
Buckets (Databases)
Friday, December 7, 12
![Page 22: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/22.jpg)
Web Admin Quick Tour!
Buckets (Databases)
Create New Bucket
Friday, December 7, 12
![Page 23: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/23.jpg)
Web Admin Quick Tour!
Buckets (Databases)
Create New Bucket
Document Browser
Friday, December 7, 12
![Page 24: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/24.jpg)
Web Admin Quick Tour!
Buckets (Databases)
Create New Bucket
Document Browser
Views (Indexes)
Friday, December 7, 12
![Page 25: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/25.jpg)
Web Admin Quick Tour!
Buckets (Databases)
Create New Bucket
Document Browser
Views (Indexes)
Friday, December 7, 12
![Page 26: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/26.jpg)
Web Admin Quick Tour!
Friday, December 7, 12
![Page 27: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/27.jpg)
Web Admin Quick Tour!
Friday, December 7, 12
![Page 28: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/28.jpg)
Friday, December 7, 12
![Page 29: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/29.jpg)
INSTALL SDK
Friday, December 7, 12
![Page 30: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/30.jpg)
Ruby
Install libcouchbase (c library)Visit h7p://www.couchbase.com/develop/c/next and install based on your OS, alternaRvely you can go to my Step-‐By-‐Step guide here:
Mac OSX Step-‐By-‐Step at h7p://CouchbaseOnRails.com/libcouchbase
h7p://www.couchbase.com/develop/c/nexth7p://www.couchbase.com/develop/ruby/next
Install Latest Couchbase Gem$ gem install couchbase -‐-‐pre
Friday, December 7, 12
![Page 31: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/31.jpg)
PHP
Install libcouchbase (c library)Visit h7p://www.couchbase.com/develop/c/next and install based on your OS, alternaRvely you can go to my Step-‐By-‐Step guide here:
Mac OSX Step-‐By-‐Step at h7p://CouchbaseOnRails.com/libcouchbase
h7p://www.couchbase.com/develop/c/nexth7p://www.couchbase.com/develop/php/next
Download PHP SDK for your OS$ tar xzf php-‐ext-‐couchbase-‐$system-‐$arch.tar.gz>> couchbase.so
Edit php.ini and add line aNer JSON extension extension=/path/to/couchbase.so
Friday, December 7, 12
![Page 32: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/32.jpg)
.NET
Use Nuget > 1.6C:\> Install-‐Package CouchbaseNetClient -‐Pre
h7p://www.couchbase.com/develop/net/next
Or, Download SDKh7p://www.couchbase.com/develop/net/next and click on DownloadPut the files in your bin folder of your project
Edit app.config <configSec=ons> and add<secRon name="couchbase" type="Couchbase.ConfiguraRon.CouchbaseClientSecRon, Couchbase" />
Edit app.config and add<couchbase>
<servers bucket="default" bucketPassword=""><add uri="h7p://127.0.0.1:8091/pools"/>
</servers></couchbase>
Friday, December 7, 12
![Page 33: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/33.jpg)
Python
Install via pip$ pip install couchbase
h7p://www.couchbase.com/develop/python/next
This is perhaps the easiest of them all!
Friday, December 7, 12
![Page 34: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/34.jpg)
Java
Download Latest Java JARSh7p://www.couchbase.com/develop/java/next
h7p://www.couchbase.com/develop/java/next
Put the JARS in your Java Classpath, or add folder to Classpath, or put under your project resources
Friday, December 7, 12
![Page 35: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/35.jpg)
Friday, December 7, 12
![Page 36: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/36.jpg)
MAKE A CONNECTION
Friday, December 7, 12
![Page 37: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/37.jpg)
RubyRuby Connec=on Op=onsrequire ‘couchbase’
c = Couchbase.connect OR c = Couchbase.bucketDefaults to 127.0.0.1:8091 and bucket “default”
c = Couchbase.connect(“hcp://[IP]:8091/pools/default/bucket/[bucket]”)
c = Couchbase.connect({:hostname => “[IP]”,:bucket => “[bucket_name]”,:password => “[bucket_password]”
})
Ruby Get & Set
c.set(“a”, 1)c.get(“a”)c.set(“a”, { :test => Time.now })c.get(“a”)
Friday, December 7, 12
![Page 38: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/38.jpg)
PHP
PHP Connec=on
// new Couchbase("[IP]:8091", "[bucket_is_user]", "[password]", "[bucket]");
<?php$cb = new Couchbase("127.0.0.1:8091", "default", "", "default");?>
PHP Set and Get
<?php$cb-‐>set("a", 1);var_dump($cb-‐>get("a"));?>
Friday, December 7, 12
![Page 39: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/39.jpg)
.NET.NET Connec=on
using Couchbase;using Enyim.Caching.Memcached;
var client = new CouchbaseClient();
OR
public staRc class CouchbaseManager{ private readonly staRc CouchbaseClient _instance; staRc CouchbaseClient() { _instance = new CouchbaseClient(); }
public staRc CouchbaseClient Instance { get { return _instance; } }}
.NET Set and Get
client.Store(StoreMode.Set, “a”, 1)client.Get(“a”)
Friday, December 7, 12
![Page 40: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/40.jpg)
Python
Python Connec=on
#!/usr/bin/env python
from couchbase.client import Couchbaseimport json
couchbase = Couchbase("127.0.0.1:8091", "default", "")
Python Set and Get
bucket = couchbase["default"]bucket.set(“a”, 0, 0, 1)bucket.get(“a”)
Friday, December 7, 12
![Page 41: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/41.jpg)
Java
Java Connec=on (1/2)
import java.net.URI;import java.uRl.LinkedList;import java.uRl.List;import java.uRl.concurrent.TimeUnit;
import com.couchbase.client.CouchbaseClient;import net.spy.memcached.CASResponse;import net.spy.memcached.internal.GetFuture;import net.spy.memcached.internal.OperaRonFuture;
Friday, December 7, 12
![Page 42: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/42.jpg)
JavaJava Connec=on (2/2)
public class HelloWorld {
public staRc void main(String args[]) { // Set the URIs and get a client List<URI> uris = new LinkedList<URI>(); Boolean do_delete = false; // Deletes the key uris.add(URI.create("h7p://127.0.0.1:8091/pools")); CouchbaseClient client = null; try { client = new CouchbaseClient(uris, "default", "", ""); } catch (ExcepRon e) { System.err.println("Error connecRng to Couchbase: " + e.getMessage()); System.exit(0); } // Shutdown the client client.shutdown(3, TimeUnit.SECONDS); System.exit(0); }}
h7p://goo.gl/yczAx
Friday, December 7, 12
![Page 43: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/43.jpg)
Friday, December 7, 12
![Page 44: CouchConf_Developer Lab](https://reader030.fdocuments.us/reader030/viewer/2022032514/55d550fabb61eb08598b45fc/html5/thumbnails/44.jpg)
OPERATIONS
Friday, December 7, 12