我尝试将文件保存到riak存储。这是我的问题的简化代码
val bytes: Array[Byte] = "bbb".toCharArray.map(_.toByte)
val client: RiakClient = RiakClient(host, port)
Await.ready(client.ping, Duration(30, TimeUnit.SECONDS))
val bucket: RiakBucket = client.bucket("fileStorage")
Await.ready(bucket.store("aaa",bytes), Duration.Inf)
我收到了下一个错误
Error:(23, 29) could not find implicit value for evidence parameter of type com.scalapenos.riak.RiakMarshaller[Array[Byte]]
Await.ready(bucket.store("aaa",bytes), Duration.Inf)
我知道我需要在bucket.store[X]("aaa",bytes)
中指定类型,但我找不到合适的类型,而我必须代替X
。
我需要在Riak
库中使用哪种类型,还是应该自己实现?
PS:我在maven中使用这个库:
<dependency>
<groupId>com.scalapenos</groupId>
<artifactId>riak-scala-client_2.11</artifactId>
<version>0.9.5</version>
</dependency>
答案 0 :(得分:0)
我无法找到解决问题的方法。所以我把库更改为
<dependency>
<groupId>com.basho.riak</groupId>
<artifactId>riak-client</artifactId>
</dependency>
然后
val location = new Location(namespace, key)
val storeValue = new RiakObject()
storeValue.setValue(BinaryValue.create(data.bytes))
val command = new StoreValue.Builder(storeValue)
.withLocation(location)
.build()
client.execute(command)
其中namespace
的类型为Namespace
,key
为String
,data.bytes
为Array[Byte]