function AerospikeStore (options) { var self = this; options = options || {}; Store.call(this, options); this.prefix = options.prefix == null ? 'sess:' : options.prefix; if (options.client) { // use connected client this.client = options.client; } else if (options.hosts) { // cluster connect this.client = aerospike.client({ hosts: options.hosts // [ { addr: '127.0.0.1', port: 3000 } ] }); } else if (options.port || options.host) { // single node w/ defaults this.client = aerospike.client({ hosts : [{ addr: options.host || default_host, port: options.port || default_port }] }); } else { // default this.client = aerospike.client({ hosts: [ { addr: '127.0.0.1', port: 3000 } ] }); } function connect_cb( err, client ) { console.log('Connect to aerospike', err, client); if (err.code !== status.AEROSPIKE_OK) { throw new Error('unable to connect to aerospike cluster') } self.client = client; console.log('connected',client.get); } console.log('the client', this.client.get); this.client.connect(connect_cb); this._ns = options.ns || 'store_session'; this._set = options.set || 'session'; // config.ENV + '-application' this.ttl = options.ttl; }
/* * initialize aerospike-session-store with passed options * @param {object} options */ function AerospikeSessionStore(options){ var self = this; options = _.defaults(options || {}, defaultOptions); Store.call(self, options); //Store = session.Store; self.prefix = options.prefix; self.ns = options.ns; self.st = options.st; self.ttl = options.ttl; //console.log(options.ns); if(options.hosts){ var hosts = options.hosts.map(function(host){ var _val = host.split(':'); var _host = _val[0]; var _port = ~~_val[1] || _default_port return { addr:_host,port:parseInt(_port)}; }); } /* connection to aerospike */ aerospike.client({ hosts:hosts, log:{ level: options.log_level }, policies: { timeout: options.time_out } }).connect(function(err,client){ if(err.code != aerospike.status.AEROSPIKE_OK){ console.error('Aerospike server connection Error : %j', err); } else { self.client = client; } }); this.getSessionId = function(sid){ if(options.hash){ return crypto.createHash(options.hash.algorithm).update(options.hash.salt + this.prefix + sid).digest('hex'); } else { return this.prefix + sid; } } };
'use strict'; var asConfig = require('./aerospike_config'); var aerospikeConfig = asConfig.aerospikeConfig(); var aerospikeDBParams = asConfig.aerospikeDBParams(); var aerospike = require('aerospike'); // Connect to the cluster var client = aerospike.client(aerospikeConfig); client.connect(function (response) { if ( response.code === 0) { // handle success console.log("\nConnection to Aerospike cluster succeeded!\n"); } else { // handle failure console.log("\nConnection to Aerospike cluster failed!\n"); console.log(response); } }); exports.checkUsername = function(req, res) { // console.log(req.body); console.log(aerospikeDBParams.dbName); var params = req.body; var key = aerospike.key(aerospikeDBParams.dbName,aerospikeDBParams.usersTable,'username:'+params.username); // Read the record from the database client.get(key, function(err, rec, meta) { // Check for errors if ( err.code === aerospike.status.AEROSPIKE_OK ) {
policies: { timeout: argv.timeout } }; /******************************************************************************* * * Perform the operation * ******************************************************************************/ function format(o) { return JSON.stringify(o, null, ' '); } aerospike.client(config).connect(function (err, client) { if ( err.code != Status.AEROSPIKE_OK ) { console.error("Error: Aerospike server connection error. ", err.message); process.exit(1); } // // Perform the operation // var options = { ns: argv.namespace, set: argv.set, bin : bin, index: index
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // * IN THE SOFTWARE. 'use strict'; var aerospike = require('aerospike'); var inquirer = require('inquirer'); var user_service = require('./scripts/user_service'); var tweet_service = require('./scripts/tweet_service'); // Connect to the Aerospike Cluster var client = aerospike.client({ hosts: [ { addr: '172.16.159.170', port: 3000 } ] }).connect(function(response) { // Check for errors if ( response.code == aerospike.status.AEROSPIKE_OK ) { // Connection succeeded console.log("Connection to the Aerospike cluster succeeded!"); } else { // Connection failed console.log("Connection to the Aerospike cluster failed. Please check cluster IP and Port settings and try again."); process.exit(0); } }); // Setup tear down process.on('exit', function() {
level: argv['log-level'], file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2 }, // default policies policies: { timeout: argv.timeout } }; /******************************************************************************* * * Perform the operation * ******************************************************************************/ var client = aerospike.client(config); if(client == null) { console.error("Client object not initialized"); process.exit(1); } client.connect(function (err, client) { if ( err.code != Status.AEROSPIKE_OK ) { console.error("Error: Aerospike server connection error. ", err.message); process.exit(1); } // // Perform the operation //
const Aerospike = require('aerospike') var namespace='test' var set='auction' var primary_key="1" console.log(require.resolve('aerospike')) var client = Aerospike.client({ hosts: [ { addr: "127.0.0.1", port: 3000 } ], log: { level: Aerospike.log.INFO }, policies: { timeout: 2000 } }) client.connect(function (error) { if (error) { // handle failure console.log('Connection to Aerospike cluster failed!') } else { // handle success console.log('Connection to Aerospike cluster succeeded!') do_put(client) } })
module.exports = function(app) { var aerospike = require("aerospike"); var client = aerospike.client({ hosts: [ { addr: "137.112.40.132", port: 3000 } ], log: { level: aerospike.log.INFO } }); client.connect(function (response) { if ( response.code === 0) { // handle success console.log("\nConnection to Aerospike cluster succeeded!\n"); } else { // handle failure console.log("\nConnection to Aerospike cluster failed!\n"); console.log(response); } }); app.post("/aerospike/addPostFilter", function(req, res) { }); app.get("/aerospike/testRoute", function(req, res) { var uid = 0; var key = aerospike.key("test", "demo", uid); // Record to be written to the database var rec = { uid: 1000, name: "user_name", dob: { mm: 12, dd: 29, yy: 1995}, friends: [1001, 1002, 1003], avatar: new Buffer([0xa, 0xb, 0xc]) }; client.put(key, rec, function(err) { // Check for err.code in the callback function. // AEROSPIKE_OK signifies the success of put operation. if ( err.code !== aerospike.status.AEROSPIKE_OK ) { console.log("error: %s", err.message); } else { console.log("PUT WORKED: " + aerospike.status); } }); client.get(key, function(err, record, metadata, key) { switch (err.code) { case aerospike.status.AEROSPIKE_OK: console.log("OK - ", key, metadata, record); res.status(200).send(record); break; case aerospike.status.AEROSPIKE_ERR_RECORD_NOT_FOUND: res.status(200).send(record); console.log("NOT_FOUND - ", key); break; default: console.log("ERR - ", err, key); } client.close(); }); }); }