Created
December 10, 2014 15:02
-
-
Save dalegaspi/af7b4e8553e3c6254c5f to your computer and use it in GitHub Desktop.
Code fragment fo inserting into Aerospike db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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