Debe aprovechar esta biblioteca:https://github.com/RedisLabs/spark-redisalong con el jar asociado necesario (según la versión de spark+scala que esté utilizando).
En mi caso, instalé 3 frascos en Spark Cluster (Scala =2.12) último Spark:
- chispa_redis_2_12_2_6_0.jar
- commons_pool2_2_10_0.jar
- jedis_3_6_0.jar
A lo largo de la configuración para conectarse a redis:
Configuración de configuración de clúster
spark.redis.auth PASSWORD
spark.redis.port 6379
spark.redis.host xxxx.xxx.cache.windows.net
Asegúrese de tener azure redis 4.0, la biblioteca podría tener problemas con 6.0. Código de muestra para enviar:
from pyspark.sql.types import StructType, StructField, StringType
schema = StructType([
StructField("id", StringType(), True),
StructField("colA", StringType(), True),
StructField("colB", StringType(), True)
])
data = [
['1', '8', '2'],
['2', '5', '3'],
['3', '3', '1'],
['4', '7', '2']
]
df = spark.createDataFrame(data, schema=schema)
df.show()
--------------
(
df.
write.
format("org.apache.spark.sql.redis").
option("table", "mytable").
option("key.column", "id").
save()
)