Installation

Documentation

Basic Usage

Operations are synchronous and some have an alternative async version using the Future. Only basic usages are shown below. Check the API docs for more information.

Create a connection

To create a client connection, specify a bucket name and vector of server URIs.

(nssample
(:require [couchbase-clj.client :as c]))
(c/defclient client {:bucket"default":uris ["http://127.0.0.1:8091/pools"]})
;; By using the default values, below will be the same.;; Default values are defined in couchbase-clj.config.
(c/defclient client)
;; You can specify options to the client;; See API Docs for more information.
(c/defclient client {:bucket"default":uris ["http://127.0.0.1:8091/pools"]
:op-timeout10000:op-queue-max-block-time20000})
;; Shutdown the client;; To avoid the client creation overhead, you don't have to do this per operation.;; In general, one client per application is enough.
(c/shutdown client)

Async write

(nssample
(:require [couchbase-clj.client :as c]
[couchbase-clj.util :as u]))
(c/defclient client)
;; Add a single key/value pair if the key does not already exist.
(deffut (c/async-add client :key11))
;=> #'sample/fut
fut
;=> #<CouchbaseCljOperationFuture@28768bdb: :pending>;; Get the result value of the Future.;; This is a blocking operation.
@fut
;=> true;; Add a Clojure collection data that will be converted to a JSON string value.
@(c/async-add-json client :key2 {:b2})
;=> true;; Replace a single key/value pair if the key exists.
@(c/async-replace client :key12)
;=> true;; Replace a single key/value pair if the key exists.
@(c/async-replace-json client :key1 [12])
;=> true;; Set a single key/value pair.;; If the key does not already exist, it will add the value.
@(c/async-set client :key33)
;=> true;; If the key exists, it will replace the value.
@(c/async-set client :key44)
;=> true ;; Set a Clojure collection data that will be converted to a JSON string value.
@(c/async-set-json client :key1 {:a1})
;=> true;; Set a single key/value pair by using the CAS method (Check And Set);; First get the current CAS ID.
(defcas-id (c/get-cas-id client :key))
;=> #'sample/cas-id;; Then set the value using CAS.;; Results will be returned in a keyword.;; See API Docs for more information.
@(c/async-set-cas client :key"1" cas-id)
;=> :ok;; Set a Clojure collection data that will be converted to a JSON string value using CAS.
@(c/async-set-cas-json client :key1 {:a1} (c/get-cas-id client :key1))
;=> :ok;; Append a value to an existing key/value pair.
@(c/async-append client :key",2" (c/get-cas-id client :key))
;=> true;; Prepend a value to an existing key/value pair
@(c/async-prepend client :key"0," (c/get-cas-id client :key))
;=> true;; Increment a value;; First create the default value (it must be a string value).
@(c/async-add client :inc"1")
;=> true;; Increment with a offset option
@(c/async-inc client :inc {:offset5})
;=> 6;; Decrement a value
@(c/async-dec client :inc)
;=> 5

Async query

Lazy query

Lazy query can be used to get the amount of documents specified per iteration.
Communication between the client and Couchbase server will only occur per iteration.
This is typically used to get a large data lazily.