Skip to content

Instantly share code, notes, and snippets.

@mnunberg
Created May 30, 2012 23:20
Show Gist options
  • Save mnunberg/2839528 to your computer and use it in GitHub Desktop.
Save mnunberg/2839528 to your computer and use it in GitHub Desktop.
^Cmnunberg@csure:/sources/couchnode$ node tests/couchbase.js
Created new handle Couchbase 0
Created new handle Couchbase 1
Created new handle Couchbase 2
Created new handle Couchbase 3
Created new handle Couchbase 4
Created new handle Couchbase 5
Created new handle Couchbase 6
Created new handle Couchbase 7
Created new handle Couchbase 8
Created new handle Couchbase 9
Requesting operations for Couchbase 0
Requesting operations for Couchbase 1
Requesting operations for Couchbase 2
Requesting operations for Couchbase 3
Requesting operations for Couchbase 4
Requesting operations for Couchbase 5
Requesting operations for Couchbase 6
Requesting operations for Couchbase 7
Requesting operations for Couchbase 8
Requesting operations for Couchbase 9
Got storage handler for Couchbase 9
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 9
Stored "key" - [9677771198406984000]
Got storage handler for Couchbase 9
Stored "key" - [5385277803569480000]
Got storage handler for Couchbase 9
Stored "key" - [12109716096698680000]
Got storage handler for Couchbase 6
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 6
Stored "key" - [16811475207185105000]
Got storage handler for Couchbase 6
Stored "key" - [18064601803500945000]
Got storage handler for Couchbase 6
Stored "key" - [654531168528367600]
Got storage handler for Couchbase 6
Stored "key" - [8028331133417423000]
Get handler for Couchbase 6
Found "key" - [prependsetappendappend]
Got storage handler for Couchbase 8
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 8
Stored "key" - [12404702971803075000]
Got storage handler for Couchbase 8
Stored "key" - [13367347392153518000]
Got storage handler for Couchbase 8
Stored "key" - [13893424123625734000]
Got storage handler for Couchbase 8
Stored "key" - [1610421288949383200]
Get handler for Couchbase 8
Found "key" - [prependprependsetappendappend]
Got storage handler for Couchbase 7
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 7
Stored "key" - [16244302029601505000]
Got storage handler for Couchbase 7
Stored "key" - [14833830921304408000]
Got storage handler for Couchbase 7
Stored "key" - [18031106281272377000]
Got storage handler for Couchbase 7
Stored "key" - [6677531620671357000]
Get handler for Couchbase 7
Found "key" - [setappend]
Got storage handler for Couchbase 5
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 5
Stored "key" - [13083064262745522000]
Got storage handler for Couchbase 5
Stored "key" - [8931026881286636000]
Got storage handler for Couchbase 5
Stored "key" - [12483523661863453000]
Got storage handler for Couchbase 5
Stored "key" - [14955436907336434000]
Get handler for Couchbase 5
Found "key" - [prependsetappend]
Got storage handler for Couchbase 9
Stored "key" - [5367545979548336000]
Get handler for Couchbase 9
Found "key" - [prependreplaced]
Got storage handler for Couchbase 2
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 2
Stored "key" - [4121466153254912000]
Got storage handler for Couchbase 2
Stored "key" - [8543719512356028000]
Got storage handler for Couchbase 2
Stored "key" - [3380624014552465400]
Got storage handler for Couchbase 2
Stored "key" - [6073214741278228000]
Get handler for Couchbase 2
Found "key" - [prependprependsetappend]
Got storage handler for Couchbase 3
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 3
Stored "key" - [8203978115954639000]
Got storage handler for Couchbase 3
Stored "key" - [11258264187753595000]
Got storage handler for Couchbase 3
Stored "key" - [16252756174507475000]
Got storage handler for Couchbase 3
Stored "key" - [14840877691326824000]
Get handler for Couchbase 3
Found "key" - [prependsetappend]
Got storage handler for Couchbase 0
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 0
Stored "key" - [1950777312350699500]
Got storage handler for Couchbase 0
Stored "key" - [7811367802443268000]
Got storage handler for Couchbase 0
Stored "key" - [10497202030216348000]
Got storage handler for Couchbase 0
Stored "key" - [17650325613364249000]
Get handler for Couchbase 0
Found "key" - [prependprependsetappendappend]
Got storage handler for Couchbase 1
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 1
Stored "key" - [1313235390589436000]
Got storage handler for Couchbase 1
Stored "key" - [11730342803674104000]
Got storage handler for Couchbase 1
Stored "key" - [10339013093304960000]
Got storage handler for Couchbase 1
Stored "key" - [8994125654581445000]
Get handler for Couchbase 1
Found "key" - [prependprependsetappendappend]
Got storage handler for Couchbase 4
Failed to store "key" [Key exists (with a different CAS value)]
Got storage handler for Couchbase 4
Stored "key" - [8489155148316017000]
Got storage handler for Couchbase 4
Stored "key" - [6926970127083504000]
Got storage handler for Couchbase 4
Stored "key" - [764639561468739600]
Got storage handler for Couchbase 4
Stored "key" - [9869792108105040000]
Get handler for Couchbase 4
Found "key" - [prependsetappend]
/* -*- Mode: JS; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2012 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// A callback function that is called from libcouchbase
// when it encounters a problem without an operation context
function errorHandler(errorMessage) {
console.log("ERROR: [" + errorMessage + "]");
process.exit(1);
}
// A callback function that is called for get requests
function getHandler(state, key, value, flags, cas) {
if (state) {
console.log("Found \"" + key + "\" - [" + value + "]");
} else {
console.log("Get failed for \"" + key + "\" [" + value + "]");
}
}
// A callback function that is called for storage requests
function storageHandler(state, key, cas) {
if (state) {
console.log("Stored \"" + key + "\" - [" + cas + "]");
} else {
console.log("Failed to store \"" + key + "\" [" + cas + "]");
}
}
// Load the driver and create an instance that connects
// to our cluster running at "myserver:8091"
var driver = require('couchbase');
var handles = [];
for (var i = 0; i < 10; i++) {
var cb = new driver.Couchbase("localhost:8091",
"Administrator",
"123456",
"membase0");
cb.id = "Couchbase " + i;
var cberr = (function(iter) {
return function() {
console.log("Error handler for " + iter);
errorHandler.apply(this, arguments);
}
})(cb.id);
cb.setErrorHandler(cberr);
var cbget = (function(iter) {
return function() {
console.log("Get handler for " + iter);
getHandler.apply(this, arguments);
}
})(cb.id);
cb.setGetHandler(cbget);
var cbset = (function(iter) {
return function() {
console.log("Got storage handler for " + iter);
storageHandler.apply(this, arguments);
}
})(cb.id);
cb.setStorageHandler(cbset);
// Try to connect to the server
if (!cb.connect()) {
console.log("Failed to connect! [" + cb.getLastError() + "]");
process.exit(1);
}
console.log("Created new handle " + cb.id);
handles[i] = cb;
}
// We set a manual delay because we don't currently have a way of being
// notified when things are connected
setTimeout(function() {
for (var i in handles) {
var cb = handles[i];
console.log("Requesting operations for " + cb.id);
cb.add("key", "add");
cb.replace("key", "replaced");
cb.set("key", "set");
cb.append("key", "append");
cb.prepend("key", "prepend");
cb.get("key");
}
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment