Last active
October 9, 2018 18:10
-
-
Save randomstatistic/fc06ffd2fb5ac8ade61c630791514da9 to your computer and use it in GitHub Desktop.
Get 200 random keys from a redis cluster
This file contains hidden or 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
import io.lettuce.core.RedisURI | |
import io.lettuce.core.cluster.{ ClusterClientOptions, ClusterTopologyRefreshOptions, RedisClusterClient } | |
import scala.util.Random | |
object MGet { | |
def main(args: Array[String]): Unit = { | |
val host = args(0) | |
val port = args(1).toInt | |
val password = args(2) | |
val uri = RedisURI.Builder | |
.redis(host) | |
.withPassword(password) | |
.withPort(port).build() | |
val topology = ClusterTopologyRefreshOptions.builder().enableAllAdaptiveRefreshTriggers().build() | |
val client = RedisClusterClient.create(uri) | |
client.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(topology).build()) | |
val connection = client.connect() | |
val api = connection.async() | |
val randomKeys = Range(1,200).map(_ => Random.alphanumeric.take(20).toList.mkString).toList | |
println("Asking for :" + randomKeys.mkString(", ")) | |
println(api.mget(randomKeys: _*).get()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment