How to use the aerospike.key function in aerospike

To help you get started, we’ve selected a few aerospike examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aerospike-edu / student-workbook / deprecated / answers / Key-valueOperations / Node / scripts / user_service.js View on Github external
var randomInterests = ["Music","Football", "Soccer", "Baseball", "Basketball", "Hockey", "Weekend Warrior", "Hiking", "Camping", "Travel", "Photography"];
  
  for (var i = start; i <= end; i++) {

    username = 'user'+i;
    password = 'pwd'+i;
    var gender = genders[Math.floor((Math.random() * 10) + 1)]
    var region = regions[Math.floor((Math.random() * 10) + 1)]
    var interests = [];
    interests.push(randomInterests[Math.floor((Math.random() * 10) + 1)]);
    interests.push(randomInterests[Math.floor((Math.random() * 10) + 1)]);
    interests.push(randomInterests[Math.floor((Math.random() * 10) + 1)]);

    userRecord = {username: username, password: password, gender: gender, region: region, tweetcount: 0, lasttweeted: 0, interests: interests};

    key = aerospike.key('test','users',username);
    client.put(key, userRecord, function(err, rec, meta) {
      if ( err.code === 0 ) {
        // The record was successfully created.        
      } else {
         console.log("ERROR: createUsers failed: ", err);
      }
    });

    console.log("Wrote user record for " + username);
  }  

};
github aerospike-edu / student-workbook / deprecated / answers / Queries / Node / scripts / tweet_service.js View on Github external
function updateTweetCount(client, username)  {
  var userKey = aerospike.key('test','users',username); 
  var operator = aerospike.operator;
  var operations = [operator.incr('tweetcount', 1),operator.read('tweetcount')];
  client.operate(userKey, operations, function(err, bins, metadata, key) {
    if ( err.code === 0 ) {
      // console.log('INFO: The tweet count now is: ' + bins.tweetcount);
    }
    else  {
      console.log('ERROR: updateTweetCount failed:\n', err);
    }
  });  
}
github aerospike-edu / student-workbook / AS101 / NodeJS / KeyValueOperations / scripts / user_service.js View on Github external
var writeRec = ()=>{   //Using Arrow function notation
    username = 'user'+i;
    password = 'pwd'+i;
    var gender = genders[Math.floor((Math.random() * 10) + 1)]
    var region = regions[Math.floor((Math.random() * 10) + 1)]
    var interests = [];
    interests.push(randomInterests[Math.floor((Math.random() * 10) + 1)]);
    interests.push(randomInterests[Math.floor((Math.random() * 10) + 1)]);
    interests.push(randomInterests[Math.floor((Math.random() * 10) + 1)]);

    userRecord = {username: username, password: password, gender: gender, region: region, tweetcount: 0, lasttweeted: 0, interests: interests};

    key = aerospike.key('test','users',username);
    client.put(key, userRecord, (err, recKey)=>{
      if ( err == null ) {
        // The record was successfully created.
        console.log("Wrote user record for " + recKey['key']);
        i++;
        if(i <= end){
          writeRec();  //recurse to write next record
        }
        else{
          callback();  //done
        }

      } else {
         console.log("ERROR: createUsers failed: ", err);
         callback();
      }
github aerospike-edu / student-workbook / deprecated / exercises / Queries / Node / scripts / tweet_service.js View on Github external
console.log("********** Create Sample Tweets **********");

  var start = Math.floor((Math.random() * 1) + 1);
  var end = Math.floor((Math.random() * 5000) + 1);
  var tweets = 0;
  var username;
  var randomTweets = ['For just $1 you get a half price download of half of the song. You will be able to listen to it just once.','People tell me my body looks like a melted candle','Come on movie! Make it start!','Byaaaayy','Please, please, win! Meow, meow, meow!','Put. A. Bird. On. It.','A weekend wasted is a weekend well spent','Would you like to super spike your meal?','We have a mean no-no-bring-bag up here on aisle two.','SEEK: See, Every, EVERY, Kind... of spot','We can order that for you. It will take a year to get there.','If you are pregnant, have a soda.','Hear that snap? Hear that clap?','Follow me and I may follow you','Which is the best cafe in Portland? Discuss...','Portland Coffee is for closers!','Lets get this party started!','How about them portland blazers!',"You got school'd, yo",'I love animals','I love my dog',"What's up Portland",'Which is the best cafe in Portland? Discuss...','I dont always tweet, but when I do it is on Tweetaspike'];

  for (var i = start; i <= end; i++) {
    username = 'user'+Math.floor((Math.random() * 10000) + 1);

    // create tweets
    tweets = Math.floor((Math.random() * 10) + 1);
    console.error("Created "+tweets+" tweets for "+username);
    for (var j = 1; j <= tweets; j++) {
      var tweetKey = aerospike.key('test','tweets',username+':'+j);
      // update tweet count
      updateTweetCount(client, username);
      client.put(tweetKey, {username: username, tweet: randomTweets[Math.floor((Math.random() * 10) + 1)], ts: randomTimestamp(new Date(2015, 0, 1), new Date())}, function(err, rec, meta) {
        if ( err.code === 0 ) {
          // tweet was successfully created          
        } else {
          // An error occurred
          console.error('ERROR: createTweets failed:\n', err);
        }
      });

      for (var k=0;k<2000000;k++){                    
        // dummy sleep. NOT FOR PROD USE.
      }

    }
github aerospike-edu / student-workbook / deprecated / answers / Queries / Node / scripts / tweet_service.js View on Github external
console.log("********** Create Sample Tweets **********");

  var start = Math.floor((Math.random() * 1) + 1);
  var end = Math.floor((Math.random() * 5000) + 1);
  var tweets = 0;
  var username;
  var randomTweets = ['For just $1 you get a half price download of half of the song. You will be able to listen to it just once.','People tell me my body looks like a melted candle','Come on movie! Make it start!','Byaaaayy','Please, please, win! Meow, meow, meow!','Put. A. Bird. On. It.','A weekend wasted is a weekend well spent','Would you like to super spike your meal?','We have a mean no-no-bring-bag up here on aisle two.','SEEK: See, Every, EVERY, Kind... of spot','We can order that for you. It will take a year to get there.','If you are pregnant, have a soda.','Hear that snap? Hear that clap?','Follow me and I may follow you','Which is the best cafe in Portland? Discuss...','Portland Coffee is for closers!','Lets get this party started!','How about them portland blazers!',"You got school'd, yo",'I love animals','I love my dog',"What's up Portland",'Which is the best cafe in Portland? Discuss...','I dont always tweet, but when I do it is on Tweetaspike'];

  for (var i = start; i <= end; i++) {
    username = 'user'+Math.floor((Math.random() * 10000) + 1);

    // create tweets
    tweets = Math.floor((Math.random() * 10) + 1);
    console.error("Created "+tweets+" tweets for "+username);
    for (var j = 1; j <= tweets; j++) {
      var tweetKey = aerospike.key('test','tweets',username+':'+j);
      // update tweet count
      updateTweetCount(client, username);
      client.put(tweetKey, {username: username, tweet: randomTweets[Math.floor((Math.random() * 10) + 1)], ts: randomTimestamp(new Date(2015, 0, 1), new Date())}, function(err, rec, meta) {
        if ( err.code === 0 ) {
          // tweet was successfully created          
        } else {
          // An error occurred
          console.error('ERROR: createTweets failed:\n', err);
        }
      });

      for (var k=0;k<2000000;k++){                    
        // dummy sleep. NOT FOR PROD USE.
      }

    }
github aerospike-edu / student-workbook / deprecated / answers / Aggregations / Node / scripts / tweet_service.js View on Github external
console.log("********** Create Sample Tweets **********");

  var start = Math.floor((Math.random() * 1) + 1);
  var end = Math.floor((Math.random() * 5000) + 1);
  var tweets = 0;
  var username;
  var randomTweets = ['For just $1 you get a half price download of half of the song. You will be able to listen to it just once.','People tell me my body looks like a melted candle','Come on movie! Make it start!','Byaaaayy','Please, please, win! Meow, meow, meow!','Put. A. Bird. On. It.','A weekend wasted is a weekend well spent','Would you like to super spike your meal?','We have a mean no-no-bring-bag up here on aisle two.','SEEK: See, Every, EVERY, Kind... of spot','We can order that for you. It will take a year to get there.','If you are pregnant, have a soda.','Hear that snap? Hear that clap?','Follow me and I may follow you','Which is the best cafe in Portland? Discuss...','Portland Coffee is for closers!','Lets get this party started!','How about them portland blazers!',"You got school'd, yo",'I love animals','I love my dog',"What's up Portland",'Which is the best cafe in Portland? Discuss...','I dont always tweet, but when I do it is on Tweetaspike'];

  for (var i = start; i <= end; i++) {
    username = 'user'+Math.floor((Math.random() * 10000) + 1);

    // create tweets
    tweets = Math.floor((Math.random() * 10) + 1);
    console.error("Created "+tweets+" tweets for "+username);
    for (var j = 1; j <= tweets; j++) {
      var tweetKey = aerospike.key('test','tweets',username+':'+j);
      // update tweet count
      updateTweetCount(client, username);
      client.put(tweetKey, {username: username, tweet: randomTweets[Math.floor((Math.random() * 10) + 1)], ts: randomTimestamp(new Date(2015, 0, 1), new Date())}, function(err, rec, meta) {
        if ( err.code === 0 ) {
          // tweet was successfully created          
        } else {
          // An error occurred
          console.error('ERROR: createTweets failed:\n', err);
        }
      });

      for (var k=0;k<2000000;k++){                    
        // dummy sleep. NOT FOR PROD USE.
      }

    }
github aerospike-edu / student-workbook / deprecated / answers / Aggregations / Node / scripts / tweet_service.js View on Github external
function updateTweetCount(client, username)  {
  var userKey = aerospike.key('test','users',username); 
  var operator = aerospike.operator;
  var operations = [operator.incr('tweetcount', 1),operator.read('tweetcount')];
  client.operate(userKey, operations, function(err, bins, metadata, key) {
    if ( err.code === 0 ) {
      // console.log('INFO: The tweet count now is: ' + bins.tweetcount);
    }
    else  {
      console.log('ERROR: updateTweetCount failed:\n', err);
    }
  });  
}
github aerospike-edu / student-workbook / AS101 / NodeJS / KeyValueOperations / scripts / tweet_service.js View on Github external
function updateTweetCount(client, username)  {  //fire and forget!
  var userKey = aerospike.key('test','users',username);
  var operator = aerospike.operator;
  var operations = [operator.incr('tweetcount', 1),operator.read('tweetcount')];
  client.operate(userKey, operations, function(err, record, metadata, key) {
    if ( err == null ) {
      console.log('INFO: Updated tweet count is: ' + record.tweetcount);
      //we don't need to tie anything to return of this callback. (fire and forget)
    }
    else  {
      console.log('ERROR: updateTweetCount failed:\n', err);
    }
  });
}
github aerospike-edu / student-workbook / AS101 / NodeJS / Queries / scripts / tweet_service.js View on Github external
function updateTweetCount(client, username)  {  //fire and forget!
  var userKey = aerospike.key('test','users',username);
  var operator = aerospike.operator;
  var operations = [operator.incr('tweetcount', 1),operator.read('tweetcount')];
  client.operate(userKey, operations, function(err, record, metadata, key) {
    if ( err == null ) {
      console.log('INFO: Updated tweet count is: ' + record.tweetcount);
      //we don't need to tie anything to return of this callback. (fire and forget)
    }
    else  {
      console.log('ERROR: updateTweetCount failed:\n', err);
    }
  });
}