You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: redis-spark-notebook.ipynb
+97-41Lines changed: 97 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@
29
29
"1. Choose **Maven** as your source and click **Search Packages**\n",
30
30
"1. Enter `redis-spark-connector` and select `com.redis:redis-spark-connector:x.y.z`\n",
31
31
"1. Finalize by clicking **Install** <br/>\n",
32
-
"Want to explore the connector's full capabilities? Check the [detailed documentation](https://redis-field-engineering.github.io/redis-spark)\n"
32
+
"Want to explore the connector's full capabilities? Check the [detailed documentation](https://redis-field-engineering.github.io/redis-spark)"
33
33
]
34
34
},
35
35
{
@@ -57,9 +57,7 @@
57
57
"## Configuring Spark with Redis Connection Details\n",
58
58
"\n",
59
59
"1. From your Redis Cloud database dashboard, find your connection endpoint under **Connect**. The string follows this pattern: `redis://<user>:<pass>@<host>:<port>`\n",
60
-
"1. In Databricks, open your cluster settings and locate **Advanced Options**. Under **Spark** in the **Spark config** text area, add your Redis connection string as both `spark.redis.read.connection.uri redis://...` and `spark.redis.write.connection.uri redis://...` parameters. This configuration applies to all notebooks using this cluster. Note that it is recommended to use secrets to store sensitive Redis URIs. Refer to the [Redis Spark documentation](https://redis-field-engineering.github.io/redis-spark/#_databricks) for more details.\n",
61
-
"\n",
62
-
"\n"
60
+
"1. In Databricks, open your cluster settings and locate **Advanced Options**. Under **Spark** in the **Spark config** text area, add your Redis connection string as both `spark.redis.read.connection.uri redis://...` and `spark.redis.write.connection.uri redis://...` parameters. This configuration applies to all notebooks using this cluster. Note that it is recommended to use secrets to store sensitive Redis URIs. Refer to the [Redis Spark documentation](https://redis-field-engineering.github.io/redis-spark/#_databricks) for more details."
63
61
]
64
62
},
65
63
{
@@ -77,7 +75,7 @@
77
75
"source": [
78
76
"## Reading from Redis\n",
79
77
"\n",
80
-
"To read data from Redis run the following code:\n"
78
+
"To read data from Redis use the following line."
81
79
]
82
80
},
83
81
{
@@ -102,6 +100,45 @@
102
100
"display(df)"
103
101
]
104
102
},
103
+
{
104
+
"cell_type": "markdown",
105
+
"metadata": {
106
+
"application/vnd.databricks.v1+cell": {
107
+
"cellMetadata": {},
108
+
"inputWidgets": {},
109
+
"nuid": "63658b45-2684-440f-9d2d-b0d84bb4af8f",
110
+
"showTitle": false,
111
+
"tableResultSettingsMap": {},
112
+
"title": ""
113
+
}
114
+
},
115
+
"source": [
116
+
"## Writing to Redis\n",
117
+
"\n",
118
+
"Let's use the `df` data we imported earlier and write it back to Redis as JSON. Refresh **Redis Insight** and notice the new JSON keys prefixed with `spark:nobel`."
"streamDs = spark.sql(\"select * from nobels\")\n",
146
-
"display(streamDs)"
183
+
"display(spark.sql(\"SELECT * FROM nobels\"))"
147
184
]
148
185
},
149
186
{
150
187
"cell_type": "markdown",
151
188
"metadata": {
152
189
"application/vnd.databricks.v1+cell": {
153
-
"cellMetadata": {},
190
+
"cellMetadata": {
191
+
"byteLimit": 2048000,
192
+
"rowLimit": 10000
193
+
},
154
194
"inputWidgets": {},
155
-
"nuid": "63658b45-2684-440f-9d2d-b0d84bb4af8f",
195
+
"nuid": "db0205c2-3764-42c7-b90b-008afa288a89",
156
196
"showTitle": false,
157
197
"tableResultSettingsMap": {},
158
198
"title": ""
159
199
}
160
200
},
161
201
"source": [
162
-
"## Writing to Redis\n",
163
-
"\n",
164
-
"1. Let's use the `df` data we imported earlier and write it back to Redis as JSON.\n",
165
-
"1. Refresh **Redis Insight** and notice the new JSON keys prefixed with `spark:write`."
202
+
"With the previously created streaming dataframe still running we can add data to the stream and see the dataframe receiving that new data. In **Redis Insight** change the \"All Key Types\" filter to only show keys of **Stream** type. Double-click on the `nobels` stream and click `New Entry`. Add the following fields: `category`: `physics`, `id`: `123`, `share`: `1`, `year`: `2025`, `firstName`, `lastName`, and `motivation`. Hit `Save` and run the query again. You should now see your entry in at the bottom of the table:"
"In **Redis Insight** select keys with the pattern `spark:nobel:*`. You should see hashes corresponding to the entries in the `nobels` that we used previously. If you add other entries to the stream like we did in the *Reading from Redis in Streaming Mode* section, you will them reflected in that `spark:nobel` keyspace."
0 commit comments