Aerospike支持使用AerospikeClient.GetHeader
方法来获取指定的bins。以下是一个使用Java的代码示例:
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import com.aerospike.client.Record;
public class AerospikeExample {
private static final String HOST = "127.0.0.1";
private static final int PORT = 3000;
private static final String NAMESPACE = "test";
private static final String SET = "exampleSet";
private static final String KEY = "exampleKey";
public static void main(String[] args) {
AerospikeClient client = new AerospikeClient(HOST, PORT);
try {
Key key = new Key(NAMESPACE, SET, KEY);
Record record = client.getHeader(null, key, "bin1", "bin2");
if (record != null) {
System.out.println("bin1: " + record.getValue("bin1"));
System.out.println("bin2: " + record.getValue("bin2"));
} else {
System.out.println("Record not found");
}
} catch (AerospikeException e) {
e.printStackTrace();
} finally {
client.close();
}
}
}
在上面的示例中,通过调用client.getHeader
方法,并传入要返回的bins的名称,即"bin1"和"bin2"。如果记录存在,则会返回包含指定bins的Record对象,否则返回null。您可以根据需要添加更多的bins名称。