Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add geoRedis #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/scala/com/redislabs/provider/redis/redisFunctions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ class RedisContext(@transient val sc: SparkContext) extends Serializable {
}
}

/**
* @param kvs RDD of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please complete the description of kvs parameter.

* @param geoName target geo's name which hold all the kvs
* @param ttl time to live
*/
def toRedisGEO(kvs: RDD[(Double,Double,String)], geoName: String, ttl: Int = 0)
(implicit
redisConfig: RedisConfig = RedisConfig.fromSparkConf(sc.getConf),
readWriteConfig: ReadWriteConfig = ReadWriteConfig.fromSparkConf(sc.getConf)) {
kvs.foreachPartition(partition => setGeo(geoName, partition, ttl, redisConfig, readWriteConfig))
}

/**
* @param kvs Pair RDD of K/V
* @param ttl time to live
Expand Down Expand Up @@ -359,6 +371,23 @@ object RedisContext extends Serializable {
conn.close()
}

/**
* @param geoName
* @param arr k/vs which should be saved in the target host
* save all the k/vs to zsetName(zset type) to the target host
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be wrong. Copy pasted from another method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @param ttl time to live
*/
def setGeo(geoName: String, arr: Iterator[(Double,Double,String)], ttl: Int, redisConfig: RedisConfig, readWriteConfig: ReadWriteConfig) {
implicit val rwConf: ReadWriteConfig = readWriteConfig
val conn = redisConfig.connectionForKey(geoName)
val pipeline = foreachWithPipelineNoLastSync(conn, arr) { case (pipeline, (lon,lat,mem)) =>
pipeline.geoadd(geoName,lon,lat,mem)
}
if (ttl > 0) pipeline.expire(geoName, ttl)
pipeline.sync()
conn.close()
}

/**
* @param zsetName
* @param arr k/vs which should be saved in the target host
Expand Down