Skip to content

Commit

Permalink
Merge pull request #4 from aerospike/develop
Browse files Browse the repository at this point in the history
v0.6.0
  • Loading branch information
reugn authored Apr 27, 2021
2 parents 45995a7 + b23bbeb commit 0a72e9a
Show file tree
Hide file tree
Showing 18 changed files with 1,524 additions and 11 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,27 @@ Operation | Description
[TOUCH](https://redis.io/commands/touch) *key [key ...]* | Alters the last access time of a key(s). A key is ignored if it does not exist.
[TTL](https://redis.io/commands/ttl) *key* | Returns the remaining time to live of a key that has a timeout.
[UNLINK](https://redis.io/commands/unlink) *key [key ...]* | This command is an alias to DEL.
[ZADD](https://redis.io/commands/zadd) *key [NX/XX] [GT/LT] [CH] [INCR] score member [score member ...]* | Adds all the specified members with the specified scores to the sorted set stored at key.
[ZCARD](https://redis.io/commands/zcard) *key* | Returns the sorted set cardinality (number of elements) of the sorted set stored at key.
[ZCOUNT](https://redis.io/commands/zcount) *key min max* | Returns the number of elements in the sorted set at key with a score between min and max.
[ZINCRBY](https://redis.io/commands/zincrby) *key increment member* | Increments the score of member in the sorted set stored at key by increment.
[ZLEXCOUNT](https://redis.io/commands/zlexcount) *key min max* | When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns the number of elements in the sorted set at key with a value between min and max.
[ZMSCORE](https://redis.io/commands/zmscore) *key member [member ...]* | Returns the scores associated with the specified members in the sorted set stored at key.
[ZPOPMAX](https://redis.io/commands/zpopmax) *key [count]* | Removes and returns up to count members with the highest scores in the sorted set stored at key.
[ZPOPMIN](https://redis.io/commands/zpopmin) *key [count]* | Removes and returns up to count members with the lowest scores in the sorted set stored at key.
[ZRANDMEMBER](https://redis.io/commands/zrandmember) *key [count [WITHSCORES]]* | When called with just the key argument, return a random element from the sorted set value stored at key.
[ZRANGE](https://redis.io/commands/zrange) *key min max [BYSCORE/BYLEX] [REV] [LIMIT offset count] [WITHSCORES]* | Returns the specified range of elements in the sorted set stored at <key>.
[ZRANGEBYLEX](https://redis.io/commands/zrangebylex) *key min max [LIMIT offset count]* | When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value between min and max.
[ZRANGEBYSCORE](https://redis.io/commands/zrangebyscore) *key min max [WITHSCORES] [LIMIT offset count]* | Returns all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max). The elements are considered to be ordered from low to high scores.
[ZRANGESTORE](https://redis.io/commands/zrangestore) *dst src min max [BYSCORE/BYLEX] [REV] [LIMIT offset count]* | This command is like ZRANGE, but stores the result in the <dst> destination key.
[ZRANK](https://redis.io/commands/zrank) *key member* | Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high.
[ZREM](https://redis.io/commands/zrem) *key member [member ...]* | Removes the specified members from the sorted set stored at key.
[ZREMRANGEBYLEX](https://redis.io/commands/zremrangebylex) *key min max* | When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command removes all elements in the sorted set stored at key between the lexicographical range specified by min and max.
[ZREMRANGEBYRANK](https://redis.io/commands/zremrangebyrank) *key start stop* | Removes all elements in the sorted set stored at key with rank between start and stop.
[ZREMRANGEBYSCORE](https://redis.io/commands/zremrangebyscore) *key min max* | Removes all elements in the sorted set stored at key with a score between min and max (inclusive).
[ZREVRANGE](https://redis.io/commands/zrevrange) *key start stop [WITHSCORES]* | Returns the specified range of elements in the sorted set stored at key.
[ZREVRANGEBYLEX](https://redis.io/commands/zrevrangebylex) *key max min [LIMIT offset count]* | Apart from the reversed ordering, ZREVRANGEBYLEX is similar to ZRANGEBYLEX.
[ZREVRANGEBYSCORE](https://redis.io/commands/zrevrangebyscore) *key max min [WITHSCORES] [LIMIT offset count]* | Returns all the elements in the sorted set at key with a score between max and min (including elements with score equal to max or min). In contrary to the default ordering of sorted sets, for this command the elements are considered to be ordered from high to low scores.

</details>

Expand Down
2 changes: 1 addition & 1 deletion 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.5.0"
version = "0.6.0"

repositories {
mavenCentral()
Expand Down
38 changes: 38 additions & 0 deletions src/main/kotlin/com/aerospike/skyhook/command/RedisCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,27 @@ import com.aerospike.skyhook.util.RedisCommandsDetails.timeCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.touchCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.ttlCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.unlinkCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zaddCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zcardCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zcountCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zincrbyCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zlexcountCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zmscoreCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zpopmaxCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zpopminCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zrandmemberCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zrangeCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zrangebylexCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zrangebyscoreCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zrangestoreCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zrankCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zremCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zremrangebylexCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zremrangebyrankCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zremrangebyscoreCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zrevrangeCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zrevrangebylexCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zrevrangebyscoreCommand
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.redis.ArrayHeaderRedisMessage
import mu.KotlinLogging
Expand Down Expand Up @@ -135,9 +154,12 @@ enum class RedisCommand(private val details: RedisCommandDetails?) {
HGETALL(hgetallCommand),
HVALS(hvalsCommand),
HKEYS(hkeysCommand),
ZMSCORE(zmscoreCommand),
ZRANK(zrankCommand),
SMEMBERS(smembersCommand),
HINCRBY(hincrbyCommand),
HINCRBYFLOAT(hincrbyfloatCommand),
ZINCRBY(zincrbyCommand),
HSTRLEN(hstrlenCommand),
HLEN(hlenCommand),
SCARD(scardCommand),
Expand All @@ -149,6 +171,22 @@ enum class RedisCommand(private val details: RedisCommandDetails?) {
SINTER(sinterCommand),
SUNIONSTORE(sunionstoreCommand),
SINTERSTORE(sinterstoreCommand),
ZADD(zaddCommand),
ZPOPMAX(zpopmaxCommand),
ZPOPMIN(zpopminCommand),
ZRANDMEMBER(zrandmemberCommand),
ZCOUNT(zcountCommand),
ZLEXCOUNT(zlexcountCommand),
ZREMRANGEBYSCORE(zremrangebyscoreCommand),
ZREMRANGEBYRANK(zremrangebyrankCommand),
ZREMRANGEBYLEX(zremrangebylexCommand),
ZRANGE(zrangeCommand),
ZRANGESTORE(zrangestoreCommand),
ZREVRANGE(zrevrangeCommand),
ZRANGEBYSCORE(zrangebyscoreCommand),
ZREVRANGEBYSCORE(zrevrangebyscoreCommand),
ZRANGEBYLEX(zrangebylexCommand),
ZREVRANGEBYLEX(zrevrangebylexCommand),

FLUSHDB(flushdbCommand),
FLUSHALL(flushallCommand),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ class NettyAerospikeHandler @Inject constructor(
RedisCommand.HGETALL,
RedisCommand.HVALS,
RedisCommand.HKEYS,
RedisCommand.ZMSCORE,
RedisCommand.ZRANK,
RedisCommand.SMEMBERS -> MapGetCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.HINCRBY,
RedisCommand.HINCRBYFLOAT -> HincrbyCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.HINCRBYFLOAT,
RedisCommand.ZINCRBY -> HincrbyCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.HSTRLEN -> HstrlenCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.HLEN,
RedisCommand.SCARD,
Expand All @@ -105,6 +108,22 @@ class NettyAerospikeHandler @Inject constructor(
RedisCommand.SINTER -> SinterCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.SUNIONSTORE -> SunionstoreCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.SINTERSTORE -> SinterstoreCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZADD -> ZaddCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZPOPMAX -> ZpopmaxCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZPOPMIN -> ZpopminCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZRANDMEMBER -> ZrandmemberCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZCOUNT -> ZcountCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZLEXCOUNT -> ZlexcountCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZREMRANGEBYSCORE -> ZremrangebyscoreCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZREMRANGEBYRANK -> ZremrangebyrankCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZREMRANGEBYLEX -> ZremrangebylexCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZRANGE -> ZrangeCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZRANGESTORE -> ZrangestoreCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZREVRANGE -> ZrevrangeCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZRANGEBYSCORE -> ZrangebyscoreCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZREVRANGEBYSCORE -> ZrevrangebyscoreCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZRANGEBYLEX -> ZrangebylexCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZREVRANGEBYLEX -> ZrevrangebylexCommandListener(aerospikeCtx, ctx).handle(cmd)

RedisCommand.FLUSHDB,
RedisCommand.FLUSHALL -> FlushCommandHandler(aerospikeCtx, ctx).handle(cmd)
Expand All @@ -129,7 +148,7 @@ class NettyAerospikeHandler @Inject constructor(
is AerospikeException -> "internal error"
else -> e.message
}
log.warn { e }
log.warn(e) {}
writeErrorString(ctx, msg)
ctx.flush()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ abstract class BaseListener(
updateOnlyPolicy
}

@JvmStatic
internal val createOnlyPolicy = run {
val updateOnlyPolicy = getWritePolicy()
updateOnlyPolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY
updateOnlyPolicy
}

@JvmStatic
internal val defaultWritePolicy: WritePolicy = getWritePolicy()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.aerospike.client.Value
import com.aerospike.client.cdt.MapOperation
import com.aerospike.client.cdt.MapPolicy
import com.aerospike.client.listener.RecordListener
import com.aerospike.skyhook.command.RedisCommand
import com.aerospike.skyhook.command.RequestCommand
import com.aerospike.skyhook.config.AerospikeContext
import com.aerospike.skyhook.listener.BaseListener
Expand All @@ -17,29 +18,48 @@ class HincrbyCommandListener(
ctx: ChannelHandlerContext
) : BaseListener(aeroCtx, ctx), RecordListener {

@Volatile
private lateinit var command: RedisCommand

override fun handle(cmd: RequestCommand) {
require(cmd.argCount == 4) { argValidationErrorMsg(cmd) }

command = cmd.command
val key = createKey(cmd.key)
val mapKey: Value = Typed.getValue(cmd.args[2])
val incrValue: Value = Typed.getValue(cmd.args[3])
val operation = MapOperation.increment(
MapPolicy(), aeroCtx.bin,
mapKey, incrValue
getMapKey(cmd), getIncrValue(cmd)
)
aeroCtx.client.operate(
null, this, defaultWritePolicy,
key, operation
)
}

private fun getMapKey(cmd: RequestCommand): Value {
return when (cmd.command) {
RedisCommand.ZINCRBY -> Typed.getValue(cmd.args[3])
else -> Typed.getValue(cmd.args[2])
}
}

private fun getIncrValue(cmd: RequestCommand): Value {
return when (cmd.command) {
RedisCommand.ZINCRBY -> Typed.getValue(cmd.args[2])
else -> Typed.getValue(cmd.args[3])
}
}

override fun onSuccess(key: Key?, record: Record?) {
if (record == null) {
writeNullString(ctx)
writeErrorString(ctx, "failed to create a record")
ctx.flush()
} else {
try {
writeResponse(record.bins[aeroCtx.bin])
when (command) {
RedisCommand.ZINCRBY -> writeResponse(record.getLong(aeroCtx.bin).toString())
else -> writeResponse(record.bins[aeroCtx.bin])
}
ctx.flush()
} catch (e: Exception) {
closeCtx(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class MapGetCommandListener(
ctx: ChannelHandlerContext
) : BaseListener(aeroCtx, ctx), RecordListener {

@Volatile
private lateinit var command: RedisCommand

override fun handle(cmd: RequestCommand) {
command = cmd.command
val key = createKey(cmd.key)

aeroCtx.client.operate(
Expand All @@ -44,7 +48,16 @@ class MapGetCommandListener(
MapReturnType.VALUE
)
}
RedisCommand.HMGET -> {
RedisCommand.ZRANK -> {
require(cmd.argCount == 3) { argValidationErrorMsg(cmd) }

val mapKey = Typed.getValue(cmd.args[2])
MapOperation.getByKey(
aeroCtx.bin, mapKey,
MapReturnType.RANK
)
}
RedisCommand.HMGET, RedisCommand.ZMSCORE -> {
require(cmd.argCount >= 3) { argValidationErrorMsg(cmd) }

val mapKeys = getValues(cmd)
Expand Down Expand Up @@ -85,7 +98,7 @@ class MapGetCommandListener(

override fun onSuccess(key: Key?, record: Record?) {
if (record == null) {
writeNullString(ctx)
writeNull()
ctx.flush()
} else {
try {
Expand All @@ -97,16 +110,31 @@ class MapGetCommandListener(
}
}

private fun writeNull() {
when (command) {
RedisCommand.HGETALL,
RedisCommand.HVALS,
RedisCommand.HKEYS,
RedisCommand.SMEMBERS ->
writeEmptyList(ctx)
else -> writeNullString(ctx)
}
}

private fun marshalOutput(data: Any?): Any? {
return when (data) {
is Map<*, *> -> data.toList()
is List<*> -> {
when (data.firstOrNull()) {
is Map.Entry<*, *> -> data.map { it as Map.Entry<*, *> }
.map { it.toPair().toList() }.flatten()
else -> data
else -> when (command) {
RedisCommand.ZMSCORE -> data.map { it.toString() }
else -> data
}
}
}
-1L -> if (command == RedisCommand.ZRANK) null else data
else -> data
}
}
Expand Down
Loading

0 comments on commit 0a72e9a

Please sign in to comment.