Skip to content

Instantly share code, notes, and snippets.

@DmitryBe
Last active February 7, 2017 08:19
Show Gist options
  • Save DmitryBe/b6c516e23cc3a93dfc9c1ca334949d62 to your computer and use it in GitHub Desktop.
Save DmitryBe/b6c516e23cc3a93dfc9c1ca334949d62 to your computer and use it in GitHub Desktop.
redis && spark
# docker image: https://hub.docker.com/_/redis/
# start redis server with append
docker run -itd --name redis --net=host -v /docker/redis/data:/data redis redis-server --appendonly yes
# start redis cli (localhost)
docker run -it --net=host --rm redis redis-cli -h localhost -p 6379
# get multiple values
MGET key1, keyN
# spark to redis
# dependencies (upload to local repo):
RedisLabs:spark-redis:0.3.2
redis.clients:jedis:2.9.0
# add to spark config(as zeppelin param)
redis.host=host_ip
# check sc params
sc.getConf.getAll.foreach(println)
# import
import com.redislabs.provider.redis._
# read from redis
sc.fromRedisKV(Array("key-1", "key-200")).collect()
# save to redis
sc.toRedisKV(pairRdd[String, String])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment