Skip to content

Commit

Permalink
Merge pull request #5 from aerospike/develop
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
reugn authored May 2, 2021
2 parents 0a72e9a + ef8f630 commit 3f3aa7d
Show file tree
Hide file tree
Showing 38 changed files with 762 additions and 88 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Operation | Description
[HLEN](https://redis.io/commands/hlen) *key* | Returns the number of fields contained in the hash stored at key.
[HMGET](https://redis.io/commands/hmget) *key field [field ...]* | Returns the values associated with the specified fields in the hash stored at key.
[HMSET](https://redis.io/commands/hmset) *key field value [field value ...]* | Sets the specified fields to their respective values in the hash stored at key.
[HSCAN](https://redis.io/commands/hscan) *key cursor [MATCH pattern] [COUNT count]* | See SCAN for HSCAN documentation.
[HSETNX](https://redis.io/commands/hsetnx) *key field value* | Sets field in the hash stored at key to value, only if field does not yet exist.
[HSET](https://redis.io/commands/hset) *key field value [field value ...]* | Sets field in the hash stored at key to value.
[HSTRLEN](https://redis.io/commands/hstrlen) *key field* | Returns the string length of the value associated with field in the hash stored at key.
Expand All @@ -77,6 +78,7 @@ Operation | Description
[INCR](https://redis.io/commands/incr) *key* | Increments the number stored at key by one.
[LINDEX](https://redis.io/commands/lindex) *key index* | Returns the element at index index in the list stored at key.
[LLEN](https://redis.io/commands/llen) *key* | Returns the length of the list stored at key.
[LOLWUT](https://redis.io/commands/lolwut) *[VERSION version]* | The LOLWUT command displays the Redis version.
[LPOP](https://redis.io/commands/lpop) *key [count]* | Removes and returns the first elements of the list stored at key.
[LPUSHX](https://redis.io/commands/lpushx) *key element [element ...]* | Inserts specified values at the head of the list stored at key, only if key already exists and holds a list.
[LPUSH](https://redis.io/commands/lpush) *key element [element ...]* | Insert all the specified values at the head of the list stored at key.
Expand All @@ -98,6 +100,7 @@ Operation | Description
[RPUSH](https://redis.io/commands/rpush) *key element [element ...]* | Insert all the specified values at the tail of the list stored at key.
[SADD](https://redis.io/commands/sadd) *key member [member ...]* | Add the specified members to the set stored at key.
[SAVE](https://redis.io/commands/save) | Returns OK.
[SCAN](https://redis.io/commands/scan) *cursor [MATCH pattern] [COUNT count] [TYPE type]* | The SCAN command and the closely related commands SSCAN, HSCAN and ZSCAN are used in order to incrementally iterate over a collection of elements.
[SCARD](https://redis.io/commands/scard) *key* | Returns the set cardinality (number of elements) of the set stored at key.
[SETEX](https://redis.io/commands/setex) *key seconds value* | Set key to hold the string value and set key to timeout after a given number of seconds.
[SETNX](https://redis.io/commands/setnx) *key value* | Set key to hold string value if key does not exist.
Expand All @@ -107,12 +110,14 @@ Operation | Description
[SISMEMBER](https://redis.io/commands/sismember) *key member* | Returns if member is a member of the set stored at key.
[SMEMBERS](https://redis.io/commands/smembers) *key* | Returns all the members of the set value stored at key.
[SREM](https://redis.io/commands/srem) *key member [member ...]* | Remove the specified members from the set stored at key.
[SSCAN](https://redis.io/commands/sscan) *key cursor [MATCH pattern] [COUNT count]* | See SCAN for SSCAN documentation.
[STRLEN](https://redis.io/commands/strlen) *key* | Returns the length of the string value stored at key. An error is returned when key holds a non-string value.
[SUNION](https://redis.io/commands/sunion) *key [key ...]* | Returns the members of the set resulting from the union of all the given sets.
[SUNIONSTORE](https://redis.io/commands/sunionstore) *destination key [key ...]* | This command is equal to SUNION, but instead of returning the resulting set, it is stored in destination.
[TIME](https://redis.io/commands/time) | Returns the current server time.
[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.
[TYPE](https://redis.io/commands/type) *key* | Returns the string representation of the type of the value stored at key. The different types that can be returned are: string, list, set, zset, hash and stream.
[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.
Expand All @@ -135,6 +140,7 @@ Operation | Description
[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.
[ZSCAN](https://redis.io/commands/zscan) *key cursor [MATCH pattern] [COUNT count]* | See SCAN for ZSCAN documentation.

</details>

Expand Down
5 changes: 3 additions & 2 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.6.0"
version = "0.7.0"

repositories {
mavenCentral()
Expand All @@ -22,7 +22,8 @@ tasks.withType<Jar> {
manifest {
attributes(
mapOf(
"Main-Class" to application.mainClassName
"Main-Class" to application.mainClassName,
"Implementation-Version" to version
)
)
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/com/aerospike/skyhook/command/RedisCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.aerospike.skyhook.util.RedisCommandsDetails.hkeysCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.hlenCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.hmgetCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.hmsetCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.hscanCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.hsetCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.hsetnxCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.hstrlenCommand
Expand All @@ -34,6 +35,7 @@ import com.aerospike.skyhook.util.RedisCommandsDetails.incrbyCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.incrbyfloatCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.lindexCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.llenCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.lolwutCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.lpopCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.lpushCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.lpushxCommand
Expand All @@ -54,6 +56,7 @@ import com.aerospike.skyhook.util.RedisCommandsDetails.rpushCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.rpushxCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.saddCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.saveCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.scanCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.scardCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.setCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.setexCommand
Expand All @@ -63,12 +66,14 @@ import com.aerospike.skyhook.util.RedisCommandsDetails.sinterstoreCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.sismemberCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.smembersCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.sremCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.sscanCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.strlenCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.sunionCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.sunionstoreCommand
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.typeCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.unlinkCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zaddCommand
import com.aerospike.skyhook.util.RedisCommandsDetails.zcardCommand
Expand All @@ -91,6 +96,7 @@ 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 com.aerospike.skyhook.util.RedisCommandsDetails.zscanCommand
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.redis.ArrayHeaderRedisMessage
import mu.KotlinLogging
Expand Down Expand Up @@ -132,6 +138,7 @@ enum class RedisCommand(private val details: RedisCommandDetails?) {
* [com.aerospike.client.AerospikeClient.exists].
*/
TOUCH(touchCommand),
TYPE(typeCommand),

LPUSH(lpushCommand),
LPUSHX(lpushxCommand),
Expand Down Expand Up @@ -188,12 +195,18 @@ enum class RedisCommand(private val details: RedisCommandDetails?) {
ZRANGEBYLEX(zrangebylexCommand),
ZREVRANGEBYLEX(zrevrangebylexCommand),

SCAN(scanCommand),
HSCAN(hscanCommand),
SSCAN(sscanCommand),
ZSCAN(zscanCommand),

FLUSHDB(flushdbCommand),
FLUSHALL(flushallCommand),
DBSIZE(dbsizeCommand),

PING(pingCommand),
ECHO(echoCommand),
LOLWUT(lolwutCommand),
TIME(timeCommand),
QUIT(null),
RESET(resetCommand),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class RequestCommand(
val argCount: Int = args.size

val key: Value by lazy {
Value.get(args[1])
Value.get(String(args[1]))
}

val command: RedisCommand by lazy {
Expand Down
13 changes: 9 additions & 4 deletions src/main/kotlin/com/aerospike/skyhook/config/AerospikeContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import com.aerospike.client.IAerospikeClient
data class AerospikeContext(

/**
* The Aerospike client instance
* The Aerospike client instance.
*/
val client: IAerospikeClient,

/**
* The namespace name to proxy to
* The Aerospike namespace to map to.
*/
val namespace: String,

/**
* The set name to proxy to
* The Aerospike set name to map to.
*/
val set: String?,

/**
* The bin name to set values
* The Aerospike bin name to set values.
*/
val bin: String,

/**
* The Aerospike bin name to set value type.
*/
val typeBin: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ data class ServerConfiguration(
*/
val bin: String = "b",

/**
* The Aerospike bin name to set value type.
*/
val typeBin: String = "t",

/**
* The server port to bind to.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import com.aerospike.skyhook.handler.redis.*
import com.aerospike.skyhook.listener.key.*
import com.aerospike.skyhook.listener.list.*
import com.aerospike.skyhook.listener.map.*
import com.aerospike.skyhook.listener.scan.HscanCommandListener
import com.aerospike.skyhook.listener.scan.ScanCommandListener
import com.aerospike.skyhook.listener.scan.SscanCommandListener
import com.aerospike.skyhook.listener.scan.ZscanCommandListener
import io.netty.channel.ChannelHandlerContext
import mu.KotlinLogging
import javax.inject.Inject
Expand All @@ -31,7 +35,8 @@ class NettyAerospikeHandler @Inject constructor(
client,
config.namespase,
config.set,
config.bin
config.bin,
config.typeBin
)

/**
Expand Down Expand Up @@ -69,6 +74,7 @@ class NettyAerospikeHandler @Inject constructor(
RedisCommand.TTL,
RedisCommand.PTTL -> TtlCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.RANDOMKEY -> RandomkeyCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.TYPE -> TypeCommandListener(aerospikeCtx, ctx).handle(cmd)

RedisCommand.LPUSH,
RedisCommand.LPUSHX,
Expand All @@ -80,8 +86,8 @@ class NettyAerospikeHandler @Inject constructor(
RedisCommand.RPOP -> ListPopCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.LRANGE -> LrangeCommandListener(aerospikeCtx, ctx).handle(cmd)

RedisCommand.HSET,
RedisCommand.HSETNX -> HsetCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.HSETNX -> HsetnxCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.HSET -> HsetCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.HMSET -> HmsetCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.SADD -> SaddCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.HEXISTS,
Expand Down Expand Up @@ -125,12 +131,18 @@ class NettyAerospikeHandler @Inject constructor(
RedisCommand.ZRANGEBYLEX -> ZrangebylexCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZREVRANGEBYLEX -> ZrevrangebylexCommandListener(aerospikeCtx, ctx).handle(cmd)

RedisCommand.SCAN -> ScanCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.HSCAN -> HscanCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.SSCAN -> SscanCommandListener(aerospikeCtx, ctx).handle(cmd)
RedisCommand.ZSCAN -> ZscanCommandListener(aerospikeCtx, ctx).handle(cmd)

RedisCommand.FLUSHDB,
RedisCommand.FLUSHALL -> FlushCommandHandler(aerospikeCtx, ctx).handle(cmd)
RedisCommand.DBSIZE -> DbsizeCommandHandler(aerospikeCtx, ctx).handle(cmd)

RedisCommand.PING -> PingCommandHandler(ctx).handle(cmd)
RedisCommand.ECHO -> EchoCommandHandler(ctx).handle(cmd)
RedisCommand.LOLWUT -> LolwutCommandHandler(ctx).handle(cmd)
RedisCommand.TIME -> TimeCommandHandler(ctx).handle(cmd)
RedisCommand.QUIT,
RedisCommand.RESET,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.aerospike.skyhook.handler.redis

import com.aerospike.skyhook.command.RequestCommand
import com.aerospike.skyhook.handler.CommandHandler
import com.aerospike.skyhook.handler.NettyResponseWriter
import com.aerospike.skyhook.listener.BaseListener
import com.aerospike.skyhook.util.SystemUtils
import io.netty.channel.ChannelHandlerContext

class LolwutCommandHandler(
private val ctx: ChannelHandlerContext
) : NettyResponseWriter(), CommandHandler {

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

writeSimpleString(ctx, "Skyhook ver. ${SystemUtils.version}\n")
ctx.flush()
}
}
36 changes: 33 additions & 3 deletions src/main/kotlin/com/aerospike/skyhook/listener/BaseListener.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.aerospike.skyhook.listener

import com.aerospike.client.AerospikeException
import com.aerospike.client.Key
import com.aerospike.client.Value
import com.aerospike.client.*
import com.aerospike.client.policy.RecordExistsAction
import com.aerospike.client.policy.WritePolicy
import com.aerospike.skyhook.command.RequestCommand
Expand Down Expand Up @@ -53,6 +51,34 @@ abstract class BaseListener(
}
}

protected fun stringTypeBin(): Bin {
return Bin(aeroCtx.typeBin, ValueType.STRING.str)
}

protected fun stringTypeOp(): Operation {
return Operation.put(stringTypeBin())
}

protected fun listTypeOp(): Operation {
return Operation.put(Bin(aeroCtx.typeBin, ValueType.LIST.str))
}

protected fun setTypeOp(): Operation {
return Operation.put(Bin(aeroCtx.typeBin, ValueType.SET.str))
}

protected fun zsetTypeOp(): Operation {
return Operation.put(Bin(aeroCtx.typeBin, ValueType.ZSET.str))
}

protected fun hashTypeOp(): Operation {
return Operation.put(Bin(aeroCtx.typeBin, ValueType.HASH.str))
}

protected fun streamTypeOp(): Operation {
return Operation.put(Bin(aeroCtx.typeBin, ValueType.STREAM.str))
}

@Throws(IOException::class)
protected open fun writeResponse(mapped: Any?) {
writeObject(ctx, mapped)
Expand All @@ -78,6 +104,10 @@ abstract class BaseListener(
return Key(aeroCtx.namespace, aeroCtx.set, key)
}

protected fun createKey(key: ByteArray): Key {
return createKey(Value.get(String(key)))
}

protected fun closeCtx(e: Exception?) {
log.error(e) { "${this.javaClass.simpleName} error" }
ctx.close()
Expand Down
17 changes: 17 additions & 0 deletions src/main/kotlin/com/aerospike/skyhook/listener/ValueType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.aerospike.skyhook.listener

/**
* Redis supported value types.
*/
enum class ValueType(val str: String) {
STRING("string"),
LIST("list"),
SET("set"),
ZSET("zset"),
HASH("hash"),
STREAM("stream");

companion object {
fun valueOf(ba: ByteArray) = valueOf(String(ba).toUpperCase())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AppendCommandListener(

val key = createKey(cmd.key)
val ops = arrayOf(
stringTypeOp(),
Operation.append(Bin(aeroCtx.bin, Value.StringValue(String(cmd.args[2])))),
Operation.get(aeroCtx.bin)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.aerospike.skyhook.listener.key

import com.aerospike.client.Key
import com.aerospike.client.Value
import com.aerospike.client.listener.ExistsArrayListener
import com.aerospike.skyhook.command.RequestCommand
import com.aerospike.skyhook.config.AerospikeContext
Expand All @@ -25,7 +24,7 @@ class ExistsCommandListener(

private fun getKeys(cmd: RequestCommand): Set<Key> {
return cmd.args.drop(1)
.map { createKey(Value.get(it)) }
.map { createKey(it) }
.toSet()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.aerospike.skyhook.listener.key

import com.aerospike.client.BatchRead
import com.aerospike.client.Key
import com.aerospike.client.Value
import com.aerospike.client.listener.BatchListListener
import com.aerospike.skyhook.command.RequestCommand
import com.aerospike.skyhook.config.AerospikeContext
Expand All @@ -18,7 +16,7 @@ class MgetCommandListener(
require(cmd.argCount >= 2) { argValidationErrorMsg(cmd) }

val keys = cmd.args.drop(1)
.map { Key(aeroCtx.namespace, aeroCtx.set, Value.get(it)) }
.map { createKey(it) }
.map { BatchRead(it, true) }
aeroCtx.client.get(null, this, null, keys)
}
Expand Down
Loading

0 comments on commit 3f3aa7d

Please sign in to comment.