Skip to content

Commit

Permalink
Merge pull request #17 from aerospike/develop
Browse files Browse the repository at this point in the history
v0.9.0
  • Loading branch information
reugn authored Jun 17, 2021
2 parents 9172201 + d1bbb9b commit 1f4cd49
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ docker run -d --name=skyhook -v "$(pwd)"/config/server.yml:/app/server.yml -p 63
| Property name | Description | Default value |
| ------------- | ----------- | ------------- |
| hostList | The host list to seed the Aerospike cluster. | localhost:3000 |
| namespase | The Aerospike namespace. | test |
| namespace | The Aerospike namespace. | test |
| set | The Aerospike set name. | redis |
| clientPolicy | The Aerospike Java client [ClientPolicy](https://docs.aerospike.com/apidocs/java/com/aerospike/client/policy/ClientPolicy.html) configuration properties. | ClientPolicyConfig |
| bin | The Aerospike value bin name. | b |
Expand Down
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.aerospike"
version = "0.8.0"
version = "0.9.0"

repositories {
mavenCentral()
Expand All @@ -30,12 +30,12 @@ tasks.withType<Jar> {
}

// Common dependency versions.
extra["nettyVersion"] = "4.1.60.Final"
extra["nettyVersion"] = "4.1.65.Final"
extra["logbackVersion"] = "1.2.3"
extra["jacksonVersion"] = "2.12.2"

dependencies {
implementation("com.aerospike:aerospike-client:5.1.2")
implementation("com.aerospike:aerospike-client:5.1.3")
implementation("io.netty:netty-all:${project.extra["nettyVersion"]}")
implementation("io.netty:netty-codec-redis:${project.extra["nettyVersion"]}")
implementation("com.google.inject:guice:5.0.1")
Expand Down
2 changes: 1 addition & 1 deletion config/server.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# The server configuration
hostList: localhost:3000
namespase: test
namespace: test
set: redis
bin: b
redisPort: 6379
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class ServerConfiguration(
/**
* The Aerospike namespace.
*/
val namespase: String = "test",
val namespace: String = "test",

/**
* The Aerospike set name.
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/com/aerospike/skyhook/listener/BaseListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ abstract class BaseListener(
writeErrorString("Internal error")
}

protected fun writeNumeric(doubleVal: Double, toFloat: Boolean = false) {
val intVal = doubleVal.toInt()
if (doubleVal == intVal.toDouble()) {
if (toFloat) {
writeBulkString(intVal.toString())
} else {
writeLong(intVal)
}
} else {
writeFloat(doubleVal)
}
}

open fun onFailure(exception: AerospikeException?) {
try {
log.debug { exception }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ abstract class UnaryCommandListener(
ctx: ChannelHandlerContext
) : BaseListener(ctx), RecordListener {

@Volatile
private lateinit var command: RedisCommand

override fun handle(cmd: RequestCommand) {
require(cmd.argCount == 2 || cmd.argCount == 3) {
argValidationErrorMsg(cmd)
}

command = cmd.command
val key = createKey(cmd.key)
val ops = arrayOf(
*systemOps(ValueType.STRING),
Expand All @@ -39,7 +43,10 @@ abstract class UnaryCommandListener(
flushCtxTransactionAware()
} else {
try {
writeObject(record.bins[aeroCtx.bin])
writeNumeric(
record.getDouble(aeroCtx.bin),
command == RedisCommand.INCRBYFLOAT
)
flushCtxTransactionAware()
} catch (e: Exception) {
closeCtx(e)
Expand All @@ -57,12 +64,9 @@ class IncrCommandListener(
override fun getUnaryOperation(cmd: RequestCommand): Operation {
return when (cmd.command) {
RedisCommand.INCR -> {
Operation.add(Bin(aeroCtx.bin, 1))
}
RedisCommand.INCRBY -> {
Operation.add(Bin(aeroCtx.bin, Typed.getInteger(cmd.args[2])))
Operation.add(Bin(aeroCtx.bin, 1.0))
}
RedisCommand.INCRBYFLOAT -> {
RedisCommand.INCRBY, RedisCommand.INCRBYFLOAT -> {
Operation.add(Bin(aeroCtx.bin, Typed.getDouble(cmd.args[2])))
}
else -> {
Expand All @@ -79,10 +83,10 @@ class DecrCommandListener(
override fun getUnaryOperation(cmd: RequestCommand): Operation {
return when (cmd.command) {
RedisCommand.DECR -> {
Operation.add(Bin(aeroCtx.bin, -1))
Operation.add(Bin(aeroCtx.bin, -1.0))
}
RedisCommand.DECRBY -> {
Operation.add(Bin(aeroCtx.bin, -Typed.getInteger(cmd.args[2])))
Operation.add(Bin(aeroCtx.bin, -Typed.getDouble(cmd.args[2])))
}
else -> {
throw IllegalArgumentException(cmd.command.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class HincrbyCommandListener(
} else {
try {
when (command) {
RedisCommand.ZINCRBY -> writeResponse(record.getLong(aeroCtx.bin).toString())
else -> writeResponse(record.bins[aeroCtx.bin])
RedisCommand.ZINCRBY -> writeBulkString(record.getLong(aeroCtx.bin).toString())
else -> writeNumeric(record.getDouble(aeroCtx.bin))
}
flushCtxTransactionAware()
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AerospikeChannelInitializer @Inject constructor(

ch.attr(aeroCtxAttrKey).set(
AerospikeContext(
config.namespase,
config.namespace,
config.set,
config.bin,
config.typeBin,
Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/com/aerospike/skyhook/util/Typed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import com.aerospike.client.Value
object Typed {

fun getValue(wireVal: ByteArray): Value {
try {
return Value.LongValue(String(wireVal).toLong())
} catch (e: NumberFormatException) {
}
try {
return Value.DoubleValue(String(wireVal).toDouble())
} catch (e: NumberFormatException) {
Expand Down
8 changes: 8 additions & 0 deletions src/test/kotlin/com/aerospike/skyhook/KeyCommandsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ class KeyCommandsTest() : SkyhookIntegrationTestBase() {
assertEquals(ok, readString())
writeCommand("${RedisCommand.INCRBYFLOAT.name} key2 7.7")
assertEquals("18.2", readFullBulkString())
writeCommand("${RedisCommand.INCRBY.name} key2 5")
assertEquals("23.2", readFullBulkString())
writeCommand("${RedisCommand.INCR.name} key2")
assertEquals("24.2", readFullBulkString())
writeCommand("${RedisCommand.INCRBYFLOAT.name} key2 0.8")
assertEquals("25", readFullBulkString())
writeCommand("${RedisCommand.INCRBY.name} key2 5")
assertEquals(30, readLong())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class SkyhookIntegrationTestBase {
init {
channel.attr(aeroCtxAttrKey).set(
AerospikeContext(
config.namespase,
config.namespace,
config.set,
config.bin,
config.typeBin,
Expand All @@ -72,7 +72,7 @@ abstract class SkyhookIntegrationTestBase {
}

protected fun aeroKey(key: Any): Key {
return Key(config.namespase, config.set, Value.get(key))
return Key(config.namespace, config.set, Value.get(key))
}

protected fun aeroBin(bin: Any): Bin {
Expand Down

0 comments on commit 1f4cd49

Please sign in to comment.