-
-
Save xinatcg/e3f09b801a8f7192bda022f779f2483c to your computer and use it in GitHub Desktop.
Get all keys and values from Redis
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
using: "net.debasishg" %% "redisclient" % "2.11" | |
// GetRedis.apply will print out all the keys and values in a csv list | |
object GetRedis { | |
import com.redis.{RedisClient, RedisClientPool} | |
def apply = { | |
val rcp = new RedisClientPool( | |
sys.env.getOrElse("REDIS_HOST", "localhost"), | |
6379 | |
) | |
val keys = rcp.withClient(c => c.keys("*")).get.flatMap { k => k } | |
val keysValues = keys map { k => rcp withClient { c => (k, c.get(k).get) } } | |
keysValues foreach { | |
case (k, v) => println(s"${k},${v}") | |
} | |
println(s"\n\nNum of keys and values = ${keys.size}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment