-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parsers, support for multiples clients and unit testing
- Loading branch information
1 parent
edab7f7
commit 02932c9
Showing
38 changed files
with
369 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 23 additions & 20 deletions
43
src/main/kotlin/br/com/devsrsouza/redissed/RedisObject.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/br/com/devsrsouza/redissed/RedissedCommands.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package br.com.devsrsouza.redissed | ||
|
||
interface RedissedCommands { | ||
|
||
/** | ||
* Set the [key] in redis with [value] | ||
*/ | ||
operator fun set(key: String, value: String) | ||
|
||
/** | ||
* Returns the value of [key] from redis or `null` if does not exist | ||
*/ | ||
operator fun get(key: String): String? | ||
|
||
/** | ||
* Returns `true` if the [key] exist in redis or `false` if does not | ||
*/ | ||
operator fun contains(key: String): Boolean | ||
|
||
/** | ||
* Remove [key] from redis and returns `true` if [key] exist or `false` if does not | ||
*/ | ||
fun del(key: String): Boolean | ||
|
||
/** | ||
* Set the expiration time of [key] in redis and returns `true` if success or `false` if does not | ||
*/ | ||
fun expire(key: String, seconds: Int): Boolean | ||
|
||
/** | ||
* Returns the seconds to expire of [key] from redis | ||
*/ | ||
fun ttl(key: String): Long | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/br/com/devsrsouza/redissed/clients/Jedis.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package br.com.devsrsouza.redissed.clients | ||
|
||
import br.com.devsrsouza.redissed.RedissedCommands | ||
import redis.clients.jedis.commands.JedisCommands | ||
|
||
val JedisCommands.redissed get() = JedisRedissedCommands(this) | ||
|
||
class JedisRedissedCommands(val commands: JedisCommands) : RedissedCommands { | ||
|
||
override fun set(key: String, value: String) { | ||
commands.set(key, value) | ||
} | ||
|
||
override fun get(key: String): String? { | ||
return commands.get(key) | ||
} | ||
|
||
override fun contains(key: String): Boolean { | ||
return commands.exists(key) | ||
} | ||
|
||
override fun del(key: String): Boolean { | ||
return commands.del(key) >= 1 | ||
} | ||
|
||
override fun expire(key: String, seconds: Int): Boolean { | ||
return commands.expire(key, seconds) == 1.toLong() | ||
} | ||
|
||
override fun ttl(key: String): Long { | ||
return commands.ttl(key) | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/br/com/devsrsouza/redissed/clients/Lettuce.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package br.com.devsrsouza.redissed.clients | ||
|
||
import br.com.devsrsouza.redissed.RedissedCommands | ||
import io.lettuce.core.api.sync.RedisCommands | ||
|
||
val RedisCommands<String, String>.redissed: LettuceRedissedCommands | ||
get() = LettuceRedissedCommands(this) | ||
|
||
class LettuceRedissedCommands(val commands: RedisCommands<String, String>) : RedissedCommands { | ||
override fun set(key: String, value: String) { | ||
commands.set(key, value) | ||
} | ||
|
||
override fun get(key: String): String? { | ||
return commands.get(key) | ||
} | ||
|
||
override fun contains(key: String): Boolean { | ||
return commands.exists(key) >= 1 | ||
} | ||
|
||
override fun del(key: String): Boolean { | ||
return commands.del(key) >= 1 | ||
} | ||
|
||
override fun expire(key: String, seconds: Int): Boolean { | ||
return commands.expire(key, seconds.toLong()) | ||
} | ||
|
||
override fun ttl(key: String): Long { | ||
return commands.ttl(key) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/br/com/devsrsouza/redissed/delegates/ParserDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package br.com.devsrsouza.redissed.delegates | ||
|
||
import br.com.devsrsouza.redissed.RedisObject | ||
import br.com.devsrsouza.redissed.get | ||
import br.com.devsrsouza.redissed.set | ||
import br.com.devsrsouza.redissed.parsers.Parser | ||
import kotlin.reflect.KProperty | ||
|
||
class ParserDelegate<T>(val parser: Parser<T>, val default: T) { | ||
operator fun getValue(ref: RedisObject, property: KProperty<*>): T { | ||
return get(ref, property)?.let { parser.parse(it) } ?: default | ||
} | ||
operator fun setValue(ref: RedisObject, property: KProperty<*>, value: T) { | ||
set(parser.render(value), ref, property) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/br/com/devsrsouza/redissed/delegates/ParserDelegateNullable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package br.com.devsrsouza.redissed.delegates | ||
|
||
import br.com.devsrsouza.redissed.RedisObject | ||
import br.com.devsrsouza.redissed.get | ||
import br.com.devsrsouza.redissed.setNullable | ||
import br.com.devsrsouza.redissed.parsers.Parser | ||
import kotlin.reflect.KProperty | ||
|
||
class ParserDelegateNullable<T>(val parser: Parser<T>) { | ||
operator fun getValue(ref: RedisObject, property: KProperty<*>): T? { | ||
return get(ref, property)?.let { parser.parse(it) } | ||
} | ||
|
||
operator fun setValue(ref: RedisObject, property: KProperty<*>, value: T?) { | ||
val render = value?.let { parser.render(it) } | ||
setNullable(render, ref, property) | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
src/main/kotlin/br/com/devsrsouza/redissed/delegates/RedisDelegate.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/main/kotlin/br/com/devsrsouza/redissed/delegates/RedisDelegateNullable.kt
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/main/kotlin/br/com/devsrsouza/redissed/delegates/notnull/BooleanRedisDelegate.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.