谁能建议我如何使用aerospike客户端检索以原始格式存储的数据,我可以从Aerospike获取所有其他类型的数据,但不能获取以原始格式存储的数据。C语言中存在等价函数,但无法在Java中找到它的等价性。
在as_record_set_raw中设置数据的C语言函数名
在as_record_get_bytes中获取数据的C语言函数名
当使用Aerospike客户端从Java获取数据时,我得到{msg=[B@6d3163a6,length=10},而消息是以原始格式存储的。
预期产出:- {msg=66 65 78 44,length=10}
已经检查了工作区的编码部分。
PS :- getBytes()不能工作,得到以下例外:- java.lang.ClassCastException:类[B不能转换为java.lang.Long类([B和java.lang.Long在加载程序‘java.lang.Long’的模块java.base中])
code
userKey = new Key("test", "testset", key);
userRecord = client.get(null, userKey);
if (userRecord != null) {
System.out.println("\nINFO: User record read successfully! Here are the details:\n");
System.out.println("msg: " + userRecord.getValue("msg")+ "\n");
}发布于 2021-05-23 03:10:41
至少在最近的javadocs中,在getBytes()对象上看不到任何Record方法。
我看到C函数as_set_record_raw()被记录为Set specified bin's value to an NULL terminated string。因此,我建议使用com.aerospike.client.Record.getString() java方法,并根据需要使用String getBytes()方法获取原始字节数组。
编辑:我在这里假设您试图通过使用C客户机编写的Java客户机读取数据。
发布于 2021-05-25 20:09:01
原始数据实际上是存储在数据库中的未编码字节。对我来说,使用最简单的方法是将数据转换为字节数组,并将字节数组转换为字符串来使用它:
userKey = new Key("test", "testset", key);
userRecord = client.get(null, userKey);
if (userRecord != null) {
byte[] myByteArray = (byte[])userRecord.getValue(msg);
System.out.println("\nINFO: User record read successfully! Here are the details:\n");
System.out.println("msg: " + Arrays.toString(myByteArray) + "\n");
}如果您希望看到处理此类数据的一些实用示例,如果我对您的代码进行了筛选,请使用Aerospike客户端代码和transactions.ipynb笔记本在国际航空公司指南笔记本中查看这个国际航空公司指南笔记本。
https://stackoverflow.com/questions/67603284
复制相似问题