-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from fe2s/split-implicits
separate core(rdd) and streaming implicits to separate packages, so t…
- Loading branch information
Showing
6 changed files
with
70 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
5 changes: 5 additions & 0 deletions
5
src/main/scala/com/redislabs/provider/redis/streaming/package.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.redislabs.provider.redis | ||
|
||
package object streaming extends RedisStreamingFunctions { | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/scala/com/redislabs/provider/redis/streaming/redisStreamingFunctions.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.redislabs.provider.redis.streaming | ||
|
||
import com.redislabs.provider.redis.{ReadWriteConfig, RedisConfig} | ||
import org.apache.spark.storage.StorageLevel | ||
import org.apache.spark.streaming.StreamingContext | ||
import org.apache.spark.streaming.dstream.InputDStream | ||
|
||
/** | ||
* RedisStreamingContext extends StreamingContext's functionality with Redis | ||
* | ||
* @param ssc a spark StreamingContext | ||
*/ | ||
class RedisStreamingContext(@transient val ssc: StreamingContext) extends Serializable { | ||
/** | ||
* @param keys an Array[String] which consists all the Lists we want to listen to | ||
* @param storageLevel the receiver' storage tragedy of received data, default as MEMORY_AND_DISK_2 | ||
* @return a stream of (listname, value) | ||
*/ | ||
def createRedisStream(keys: Array[String], | ||
storageLevel: StorageLevel = StorageLevel.MEMORY_AND_DISK_2) | ||
(implicit | ||
redisConfig: RedisConfig = RedisConfig.fromSparkConf(ssc.sparkContext.getConf)): | ||
RedisInputDStream[(String, String)] = { | ||
new RedisInputDStream(ssc, keys, storageLevel, redisConfig, classOf[(String, String)]) | ||
} | ||
|
||
/** | ||
* @param keys an Array[String] which consists all the Lists we want to listen to | ||
* @param storageLevel the receiver' storage tragedy of received data, default as MEMORY_AND_DISK_2 | ||
* @return a stream of (value) | ||
*/ | ||
def createRedisStreamWithoutListname(keys: Array[String], | ||
storageLevel: StorageLevel = StorageLevel.MEMORY_AND_DISK_2) | ||
(implicit | ||
redisConf: RedisConfig = RedisConfig.fromSparkConf(ssc.sparkContext.getConf)): | ||
RedisInputDStream[String] = { | ||
new RedisInputDStream(ssc, keys, storageLevel, redisConf, classOf[String]) | ||
} | ||
|
||
def createRedisXStream(consumersConfig: Seq[ConsumerConfig], | ||
storageLevel: StorageLevel = StorageLevel.MEMORY_AND_DISK_2) | ||
(implicit | ||
redisConfig: RedisConfig = RedisConfig.fromSparkConf(ssc.sparkContext.getConf)): | ||
InputDStream[StreamItem] = { | ||
val readWriteConfig = ReadWriteConfig.fromSparkConf(ssc.sparkContext.getConf) | ||
val receiver = new RedisStreamReceiver(consumersConfig, redisConfig, readWriteConfig, storageLevel) | ||
ssc.receiverStream(receiver) | ||
} | ||
} | ||
|
||
trait RedisStreamingFunctions { | ||
|
||
implicit def toRedisStreamingContext(ssc: StreamingContext): RedisStreamingContext = new RedisStreamingContext(ssc) | ||
|
||
} | ||
|
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