-
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.
Merge pull request #16 from scoquelin/poc-cache-client
Add support for testing operations with LongCodec
- Loading branch information
Showing
5 changed files
with
166 additions
and
37 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
49 changes: 49 additions & 0 deletions
49
modules/tests/it/src/test/scala/com/github/scoquelin/arugula/CachedClients.scala
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,49 @@ | ||
package com.github.scoquelin.arugula | ||
|
||
import com.github.scoquelin.arugula.codec.RedisCodec | ||
import com.github.scoquelin.arugula.codec.LongCodec | ||
import com.github.scoquelin.arugula.config.LettuceRedisClientConfig | ||
import io.lettuce.core.codec.{StringCodec => JStringCodec, RedisCodec => JRedisCodec} | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
sealed trait RedisConnectionType | ||
|
||
case object SingleNode extends RedisConnectionType | ||
|
||
case object Cluster extends RedisConnectionType | ||
|
||
trait CachedClients { | ||
def getClient[K, V](codec: RedisCodec[K, V], connectionType: RedisConnectionType): RedisCommandsClient[K, V] | ||
} | ||
|
||
private class RedisCommandCachedClients(redisSingleNodeClientWithStringValue: RedisCommandsClient[String, String], | ||
redisSingleNodeClientWithLongValue: RedisCommandsClient[String, Long], | ||
redisClusterClientWithStringValue: RedisCommandsClient[String, String], | ||
redisClusterClientWithLongValue: RedisCommandsClient[String, Long]) extends CachedClients { | ||
|
||
def getClient[K, V](codec: RedisCodec[K, V], connectionType: RedisConnectionType): RedisCommandsClient[K, V] = { | ||
(codec, connectionType) match { | ||
case (RedisCodec(JStringCodec.UTF8), SingleNode) => redisSingleNodeClientWithStringValue.asInstanceOf[RedisCommandsClient[K, V]] | ||
case (RedisCodec(JStringCodec.UTF8), Cluster) => redisClusterClientWithStringValue.asInstanceOf[RedisCommandsClient[K, V]] | ||
case (RedisCodec(LongCodec), SingleNode) => redisSingleNodeClientWithLongValue.asInstanceOf[RedisCommandsClient[K, V]] | ||
case (RedisCodec(LongCodec), Cluster) => redisClusterClientWithLongValue.asInstanceOf[RedisCommandsClient[K, V]] | ||
case (codec, connectionType) => throw new IllegalStateException(s"Codec $codec not supported for connection type $connectionType") | ||
} | ||
} | ||
} | ||
|
||
object RedisCommandCachedClients { | ||
def apply(singleNodeConfig: LettuceRedisClientConfig, clusterConfig: LettuceRedisClientConfig)(implicit ec: ExecutionContext): CachedClients = { | ||
val redisSingleNodeClientWithStringValue = LettuceRedisCommandsClient(singleNodeConfig, RedisCodec.Utf8WithValueAsStringCodec) | ||
val redisSingleNodeClientWithLongValue = LettuceRedisCommandsClient(singleNodeConfig, RedisCodec.Utf8WithValueAsLongCodec) | ||
val redisClusterClientWithStringValue = LettuceRedisCommandsClient(clusterConfig, RedisCodec.Utf8WithValueAsStringCodec) | ||
val redisClusterClientWithLongValue = LettuceRedisCommandsClient(clusterConfig, RedisCodec.Utf8WithValueAsLongCodec) | ||
new RedisCommandCachedClients( | ||
redisSingleNodeClientWithStringValue, | ||
redisSingleNodeClientWithLongValue, | ||
redisClusterClientWithStringValue, | ||
redisClusterClientWithLongValue | ||
) | ||
} | ||
} |
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