Skip to content

Commit

Permalink
Minor fixes and improvements (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored Apr 23, 2023
1 parent d0d825c commit 36c3888
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class MsetCommandListener(

private fun getValues(cmd: RequestCommand): Map<Key, Value> {
return cmd.args.drop(1).chunked(2)
.map { (it1, it2) -> createKey(it1) to Typed.getValue(it2) }
.toMap()
.associate { (it1, it2) -> createKey(it1) to Typed.getValue(it2) }
}

override fun onSuccess(key: Key?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ open class SaddCommandListener(
}

protected open fun getValues(cmd: RequestCommand): Map<Value, Value> {
return cmd.args.drop(2)
.map { Typed.getValue(it) to Value.getAsNull() }
.toMap()
return cmd.args.drop(2).associate { Typed.getValue(it) to Value.getAsNull() }
}

override fun writeError(e: AerospikeException?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,9 @@ class ZaddCommandListener(
}

private fun setSortedSetValues(from: Int) {
values = cmd.args.drop(from).chunked(2)
.map { (it1, it2) ->
Typed.getStringValue(it2) to
Value.LongValue(Typed.getLong(it1))
}
.toMap()
values = cmd.args.drop(from).chunked(2).associate { (it1, it2) ->
Typed.getStringValue(it2) to Value.LongValue(Typed.getLong(it1))
}
}

private fun validate() {
Expand Down Expand Up @@ -111,6 +108,7 @@ class ZaddCommandListener(
zaddCommand.values.values.first()
)
}

else -> {
MapOperation.putItems(
getMapPolicy(),
Expand All @@ -126,9 +124,11 @@ class ZaddCommandListener(
zaddCommand.XX -> {
MapWriteFlags.UPDATE_ONLY
}

zaddCommand.NX -> {
MapWriteFlags.CREATE_ONLY
}

else -> {
MapWriteFlags.DEFAULT
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ class ZrangestoreCommandListener(
val putOperation = MapOperation.putItems(
MapPolicy(),
aeroCtx.bin,
(record.bins[aeroCtx.bin] as List<Map.Entry<Any, Long>>).map {
Typed.getValue(it.key.toString().toByteArray()) to
Value.get(it.value)
}.toMap()
(record.bins[aeroCtx.bin] as List<Map.Entry<Any, Long>>).associate {
Typed.getValue(it.key.toString().toByteArray()) to Value.get(it.value)
}
)
client.operate(
null, this, defaultWritePolicy,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/aerospike/skyhook/util/Merge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IntersectMerge : Merge {
if (data.isEmpty()) {
return setOf()
}
return data.reduce { acc, l -> acc.intersect(l.filterNotNull()) }
return data.reduce { acc, l -> acc.intersect(l.filterNotNull().toSet()) }
.filterNotNull().toSet()
}
}
3 changes: 2 additions & 1 deletion src/main/kotlin/com/aerospike/skyhook/util/Typed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import java.nio.charset.StandardCharsets

object Typed {

@Suppress("kotlin:S108")
fun getValue(wireVal: ByteArray): Value {
try {
return Value.DoubleValue(String(wireVal).toDouble())
} catch (e: NumberFormatException) {
} catch (ignore: NumberFormatException) {
}
try {
StandardCharsets.UTF_8.newDecoder().decode(ByteBuffer.wrap(wireVal))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ data class AuthDetails(
val user: String,
val password: String
) {
@Suppress("UnstableApiUsage")
val hashString: String by lazy {
Hashing.sha256()
.hashBytes(toString().encodeToByteArray())
Expand Down

0 comments on commit 36c3888

Please sign in to comment.