Skip to content

Instantly share code, notes, and snippets.

@dalegaspi
Created December 10, 2014 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalegaspi/af7b4e8553e3c6254c5f to your computer and use it in GitHub Desktop.
Save dalegaspi/af7b4e8553e3c6254c5f to your computer and use it in GitHub Desktop.
Code fragment fo inserting into Aerospike db
ClientPolicy cp = new ClientPolicy();
cp.maxThreads = 5000;
Stopwatch stopwatch = Stopwatch.createStarted();
final AerospikeClient client = new AerospikeClient(cp, "localhost", 3000);
stopwatch.stop();
System.out.println("aerospike connect elapsed = " + stopwatch.elapsed(TimeUnit.MILLISECONDS));
final WritePolicy wPolicy = new WritePolicy();
wPolicy.recordExistsAction = RecordExistsAction.UPDATE;
wPolicy.priority = Priority.HIGH;
IndexTask task = client.createIndex(null, "k2", "songs",
"artist_index", "artist", IndexType.STRING);
task.waitTillComplete(100);
FluentIterable.from(src).forEach(new Consumer < k2.Song > () {@Override
public void accept(k2.Song song) {
Key key = new Key("k2", "songs", song._id);
Bin title_bin = new Bin("title", song.title);
//client.put(wPolicy, key, title_bin);
Bin artist_bin = new Bin("artist", song.artist);
Bin album_bin = new Bin("album", song.album);
Bin random_pt_bin = new Bin("random_x", song.random_point_x);
Bin duration_bin = new Bin("duration", song.getSongDurationInSec());
//Bin metadata_bin = new Bin("metadata", song.metadata);
//client.put(wPolicy, key, title_bin, artist_bin, album_bin, random_pt_bin, duration_bin, metadata_bin);
//client.put(wPolicy, key, title_bin, artist_bin, album_bin, random_pt_bin, duration_bin);
client.put(wPolicy, key, title_bin);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment