import io.github.spencerpark.ijava.IJava;
import io.github.spencerpark.jupyter.kernel.magic.common.Shell;
IJava.getKernelInstance().getMagics().registerMagics(Shell.class);
%sh asd
%%loadFromPOM
com.aerospike
aerospike-client
5.0.0
import com.aerospike.client.AerospikeClient;
AerospikeClient client = new AerospikeClient("localhost", 3000);
System.out.println("Initialized the client and connected to the cluster.");
import com.aerospike.client.Key;
String namespaceName = "test";
String setName = "dm101set";
Integer theKey = 0; // A key can be an integer, string, or blob.
Key key = new Key(namespaceName, setName, theKey);
System.out.println("Key created." );
import com.aerospike.client.Bin;
import com.aerospike.client.policy.ClientPolicy;
String aString = "modeling";
Integer anInteger = 8;
String stringBinName = "str";
String integerBinName = "int";
ClientPolicy clientPolicy = new ClientPolicy();
Bin bin0 = new Bin(stringBinName, aString);
Bin bin1 = new Bin(integerBinName, anInteger);
client.put(clientPolicy.writePolicyDefault, key, bin0, bin1);
System.out.println("Put data into Aerospike: " + stringBinName + "=" + aString + ", " + integerBinName + "=" + anInteger);
import com.aerospike.client.Record;
Record record = client.get(null, key);
System.out.println("Generation count: " + record.generation);
System.out.println("Record expiration: " + record.expiration);
System.out.println("Bins: " + record.bins);
import com.aerospike.client.Value;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
ArrayList aTuple = new ArrayList();
aTuple.add(Value.get(9.92));
aTuple.add(Value.get("Carl Lewis"));
aTuple.add(Value.get("Seoul, South Korea"));
aTuple.add(Value.get("September 24, 1988"));
String tupleBinName = "tuple";
Bin bin2 = new Bin(tupleBinName, aTuple);
client.put(clientPolicy.writePolicyDefault, key, bin2);
Record record = client.get(null, key);
System.out.println("Put data into Aerospike: " + tupleBinName + "=" + aTuple);
System.out.println("After operation, Bins: " + record.bins);
System.out.println( tupleBinName + ": " + record.getValue(tupleBinName));
import java.util.HashMap;
String tupleMapKey = "world-records";
ArrayList tupleList = new ArrayList();
tupleList.add(Value.get(aTuple));
HashMap wrMap = new HashMap ();
wrMap.put(tupleMapKey, tupleList);
Bin bin2 = new Bin(tupleBinName, wrMap);
client.put(clientPolicy.writePolicyDefault, key, bin2);
Record record = client.get(null, key);
System.out.println("After operation, " + tupleBinName + ": " + record.getValue(tupleBinName));
import com.aerospike.client.policy.InfoPolicy;
InfoPolicy infoPolicy = new InfoPolicy();
client.truncate(infoPolicy, namespaceName, setName, null);
System.out.println("Set Truncated.");
client.close();
System.out.println("Server connection(s) closed.");
// Import Java Libraries
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
// Import Aerospike Client Libraries
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.Key;
import com.aerospike.client.Bin;
import com.aerospike.client.policy.ClientPolicy;
import com.aerospike.client.Value;
import com.aerospike.client.Record;
import com.aerospike.client.policy.InfoPolicy;
InfoPolicy infoPolicy = new InfoPolicy();
// Start the Aerospike Client.
AerospikeClient client = new AerospikeClient("localhost", 3000);
System.out.println("Initialized the client and connected to the cluster.");
// Create a Key using Namespace Set and User Key
String namespaceName = "test";
String setName = "dm101set";
Integer theKey = 0; // A key can be any value.
Key key = new Key(namespaceName, setName, theKey);
System.out.println("Key created." );
// Create Bins of Data.
// A. Integer
Integer anInteger = 8;
String integerBinName = "int";
ClientPolicy clientPolicy = new ClientPolicy();
Bin bin0 = new Bin(integerBinName, anInteger);
// B. String
String aString = "modeling";
String stringBinName = "str";
Bin bin1 = new Bin(stringBinName, aString);
// C. List
ArrayList aTuple = new ArrayList();
aTuple.add(Value.get(9.92));
aTuple.add(Value.get("Carl Lewis"));
aTuple.add(Value.get("Seoul, South Korea"));
aTuple.add(Value.get("September 24, 1988"));
String tupleBinName = "tuple";
Bin bin2 = new Bin(tupleBinName, aTuple);
client.put(clientPolicy.writePolicyDefault, key, bin2);
// D. Map
String mapTupleBinName = "maptuple";
String tupleMapKey = "world-records";
ArrayList tupleList = new ArrayList();
tupleList.add(Value.get(aTuple));
HashMap wrMap = new HashMap ();
wrMap.put(tupleMapKey, tupleList);
Bin bin3 = new Bin(mapTupleBinName, wrMap);
// Put the Bins into Aerospike
client.put(clientPolicy.writePolicyDefault, key, bin0, bin1, bin2, bin3);
// Get the Record from Aerospike.
Record record = client.get(null, key);
System.out.println("Read from Aerospike –");
System.out.println("Generation count: " + record.generation);
System.out.println("Record expiration: " + record.expiration);
System.out.println( integerBinName + ": " + record.getValue(integerBinName));
System.out.println( stringBinName + ": " + record.getValue(stringBinName));
System.out.println( tupleBinName + ": " + record.getValue(tupleBinName));
System.out.println( mapTupleBinName + ": " + record.getValue(mapTupleBinName));
// Truncate the Set.
client.truncate(infoPolicy, namespaceName, setName, null);
System.out.println("Set Truncated.");
// Close Client Connections.
client.close();
System.out.println("Server connection(s) closed.");