Java program to insert value in Aerospike database is not working


#1

I have written a java program to insert an integer and a double in aerospike database. Here is the code snippet

import java.util.Random;

import com.aerospike.client.AerospikeClient;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import com.aerospike.client.policy.WritePolicy;

public class Test{

	public static void main(String[] args){
		try{
			AerospikeClient client = new AerospikeClient("192.168.140.62", 3000);
			
			for(int i=0;i<10000;i++){
				try {
					WritePolicy writePolicy =  new WritePolicy();
					Key key = new Key("test" , "myset", "mykey");
					double randomDouble = Math.random();
					Bin bin1 = new Bin("ID",i);
					Bin bin2 = new Bin("Value",randomDouble);
					
					client.put(writePolicy,key,bin1,bin2);
					
				} catch (Exception e) {
					e.printStackTrace();
				}	
			}
			client.close();
			
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}

The problem is the above code snippet is neither inserting any data nor throwing any errors. Please advise. PS: I am new to aerospike


#2

Hi,

I am able execute without any modification except the hostname.

Below is the result after execution.

aql> select * from test.myset where pk='mykey'
+----+---------------------+
| ID | Value               |
+----+---------------------+
| 9  | 4589745104084075448 |
+----+---------------------+
1 row in set (0.001 secs)

#3

Yes even I figured that out, I was actually firing a wrong query in aql - my bad. Is there a way to read all the records of a particular set at one go?


#4

Hi,

Yes, but you need to paginate it. Else you will get timed out.

Thanks, Dhanasekaran