Cassandra Database(4) Kryo
Really useful document, I need to read them when I have time if I plan to deal with cassandra database.
http://www.datastax.com/documentation/cassandra/1.2/index.html?pagename=docs&version=1.2&file=index
1. Kryo Introduce
The latest version from the official website is 2.21. Adding to build.sbt
I only try a simple example for java HashMap
package com.sillycat.easycassandraserver.apps
import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.io.{Input, Output}
import java.util.{ HashMap => JMap }
object KryoDemoApp extends App{
//java HashMap
val maps = new JMap[String, Any]()
maps.put("productName", "iphone4s")
maps.put("price", 21.33)
val kryo = new Kryo
//transfer HashMap to bytes
val out1 = new Output(new Array[Byte](4096))
kryo.writeObject(out1, maps)
out1.close
val outputBytes1 = out1.toBytes
println("outputBytes1 of Map = " + outputBytes1)
//read the bytes back to HashMap
val in1 = new Input(outputBytes1)
val outputMap1 = kryo.readObject(in1,classOf[JMap[String, Any]])
in1.close
println("outputMap1 of Map = " + outputMap1)
}
The output should be as follow:
outputBytes1 of Map = [B@6581ed9e
outputMap1 of Map = {price=21.33, productName=iphone4s}
2. Chill
https://github.com/twitter/chill
That is a extensions for the KRYO.
…snip...
References:
http://www.datastax.com/documentation/cassandra/1.2/index.html?pagename=docs&version=1.2&file=index
Kryo
https://code.google.com/p/kryo/
http://blog.youkuaiyun.com/hengyunabc/article/details/7764509
Chill
https://github.com/twitter/chill
Cassandra Database(4) Kryo
Cassandra与Kryo实践
最新推荐文章于 2024-04-22 23:43:21 发布
本文介绍了使用Kryo序列化库来处理Cassandra数据库中Java HashMap的实例。通过示例展示了如何将HashMap转换为字节流并反序列化回原始数据结构的过程。此外还提到了Chill库作为Kryo的扩展。
568

被折叠的 条评论
为什么被折叠?



