Skip to content

Instantly share code, notes, and snippets.

@randomstatistic
Last active October 9, 2018 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomstatistic/fc06ffd2fb5ac8ade61c630791514da9 to your computer and use it in GitHub Desktop.
Save randomstatistic/fc06ffd2fb5ac8ade61c630791514da9 to your computer and use it in GitHub Desktop.
Get 200 random keys from a redis cluster
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