Skip to content

Instantly share code, notes, and snippets.

@yutaono
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutaono/b4c28359905d8f016443 to your computer and use it in GitHub Desktop.
Save yutaono/b4c28359905d8f016443 to your computer and use it in GitHub Desktop.
Aerospike Int Long Spec: Aerospikeのjava clientで値の範囲によって自動的に型が変更される仕様の確認
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))
}
@yutaono
Copy link
Author

yutaono commented May 15, 2015

result

Int.MaxValue: 2147483647
r1: 2147483646: Int
r2: 2147483647: Int
r3: 2147483648: Long
r3: 2147483647: Int

@yutaono
Copy link
Author

yutaono commented May 15, 2015

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.

Supported Data Types | Java Client Manual | Aerospike

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment