Skip to content

Instantly share code, notes, and snippets.

@jamesthompson
Created March 18, 2014 16:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamesthompson/9623474 to your computer and use it in GitHub Desktop.
Save jamesthompson/9623474 to your computer and use it in GitHub Desktop.
Get all keys and values from Redis
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