Skip to content

Commit 4965db9

Browse files
authored
Merge pull request #166 from fe2s/more-docs-and-delete-sbt
More docs and delete sbt
2 parents 9969b23 + 25e1031 commit 4965db9

File tree

4 files changed

+75
-37
lines changed

4 files changed

+75
-37
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This library is a work in progress so the API may change before the official rel
4444
- [Java](doc/java.md)
4545
- [Python](doc/python.md)
4646
- [Configuration](doc/configuration.md)
47+
- [Dev environment](doc/dev.md)
4748

4849
## Contributing
4950

build.sbt

Lines changed: 0 additions & 37 deletions
This file was deleted.

doc/dev.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### Development Environment
2+
3+
Spark-Redis is built using [Apache Maven](https://maven.apache.org/) and a helper [GNU Make](https://www.gnu.org/software/make/) file.
4+
Maven is used to build a jar file and run tests. Makefile is used to start and stop redis instances required for integration tests.
5+
6+
The `Makefile` expects that Redis binaries (`redis-server` and`redis-cli`) are in your `PATH` environment variable.
7+
8+
To build Spark-Redis and run tests, run:
9+
10+
```
11+
make package
12+
```
13+
14+
To run tests:
15+
16+
```
17+
make test
18+
```
19+
20+
If you would like to run tests from your IDE, you have to start Redis test instances with `make start` before that. To stop test
21+
instances, run `make stop`.
22+
23+
To build Spark-Redis skipping tests, run:
24+
25+
```
26+
mvn clean package -DskipTests
27+
```

doc/structured-streaming.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,53 @@ xadd sensors * sensor-id 2 temperature 30.5
3939
xadd sensors * sensor-id 1 temperature 28.3
4040
```
4141

42+
### Output to Redis
43+
44+
There is no Redis Sink available, but you can leverage [`foreachBatch`](https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#foreachbatch) and [DataFrame](dataframe.md) write command to output
45+
stream into Redis. Please note, `foreachBatch` is only available starting from Spark 2.4.0.
46+
47+
```scala
48+
val query = sensors
49+
.writeStream
50+
.outputMode("update")
51+
.foreachBatch { (batchDF: DataFrame, batchId: Long) =>
52+
batchDF
53+
.write
54+
.format("org.apache.spark.sql.redis")
55+
.option("table", "output")
56+
.mode(SaveMode.Append)
57+
.save()
58+
}
59+
.start()
60+
61+
query.awaitTermination()
62+
```
63+
64+
After writing the following to the Redis Stream:
65+
```
66+
xadd sensors * sensor-id 1 temperature 28.1
67+
xadd sensors * sensor-id 2 temperature 30.5
68+
xadd sensors * sensor-id 1 temperature 28.3
69+
```
70+
71+
there will be the output `keys output:*`:
72+
```
73+
1) "output:b1682af092b9467cb13cfdcf7fcc9835"
74+
2) "output:04c80769320f4edeadcce8381a6f834d"
75+
3) "output:4f04070a2fd548fdbea441b694c8673b"
76+
```
77+
78+
`hgetall output:b1682af092b9467cb13cfdcf7fcc9835`:
79+
80+
```
81+
1) "sensor-id"
82+
2) "2"
83+
3) "temperature"
84+
4) "30.5"
85+
```
86+
87+
Please refer to [DataFrame docs](dataframe.md) for different options(such as specifying key name) available for writing .
88+
4289
### Stream Offset
4390

4491
By default it pulls messages starting from the latest message in the stream. If you need to start from the specific position in the stream, specify the `stream.offsets` parameter as a JSON string.

0 commit comments

Comments
 (0)