Last active
August 29, 2015 14:21
-
-
Save yutaono/b4c28359905d8f016443 to your computer and use it in GitHub Desktop.
Aerospike Int Long Spec: Aerospikeのjava clientで値の範囲によって自動的に型が変更される仕様の確認
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.aerospike.client.policy.ClientPolicy | |
import com.aerospike.client.{AerospikeClient, Bin, Key} | |
object AerospikeIntLongSpec extends App { | |
val policy = new ClientPolicy | |
policy.user = ""; policy.password = "" | |
val client = new AerospikeClient(policy, "127.0.0.1", 3000) | |
val (keyName, binName) = ("budget", "spend") | |
val key = new Key("test", "budgetSet", keyName) | |
def getTypeAndValue(value: AnyVal) = value match { | |
case i: Int => s"$i: Int" | |
case i: Long => s"$i: Long" | |
} | |
client.delete(null, key) | |
println("Int.MaxValue: " + Int.MaxValue) | |
client.put(null, key, new Bin(binName, Int.MaxValue - 1)) | |
val r1 = client.get(null, key).getValue(binName).asInstanceOf[AnyVal] | |
println("r1: " + getTypeAndValue(r1)) | |
client.add(null, key, new Bin(binName, 1)) | |
val r2 = client.get(null, key).getValue(binName).asInstanceOf[AnyVal] | |
println("r2: " + getTypeAndValue(r2)) | |
client.add(null, key, new Bin(binName, 1)) | |
val r3 = client.get(null, key).getValue(binName).asInstanceOf[AnyVal] | |
println("r3: " + getTypeAndValue(r3)) | |
client.add(null, key, new Bin(binName, -1)) | |
val r4 = client.get(null, key).getValue(binName).asInstanceOf[AnyVal] | |
println("r3: " + getTypeAndValue(r4)) | |
} |
When setting a value in Java, the Aerospike library automatically determine the best Aerospike native type for storage. Integers and Longs are converted into an internal number format, and Strings are converted to UTF-8. Byte arrays are stored as blobs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result