@@ -8,7 +8,7 @@ Integrating Redis and Spark gives us a system that combines the best of both wor
8
8
9
9
## Requirements
10
10
11
- This library requires Apache Spark 1.4+, Scala 2.10.4+, Jedis 2.7+, Redis 3.0 +
11
+ This library requires Apache Spark 1.4+, Scala 2.10.4+, Jedis 2.7+, Redis 2.8 +
12
12
13
13
## Current Limitations
14
14
* No Java or Python API bindings
@@ -77,20 +77,95 @@ To read data from Redis Server, you can use the library by loading the implicits
77
77
78
78
In the example we can see how to read from Redis Server.
79
79
```
80
- scala> import com.redislabs.provider.redis._
81
- scala> val keysRDD = sc.fromRedisKeyPattern(("127.0.0.1", 7000), "*", 5)
82
- scala> val kvRDD = keysRDD.getKV
83
- scala> val hashRDD = keysRDD.getHash
84
- scala> val zsetRDD = keysRDD.getZSet
85
- scala> val listRDD = keysRDD.getList
86
- scala> val setRDD = keysRDD.getSet
80
+ import com.redislabs.provider.redis._
81
+ val keysRDD = sc.fromRedisKeyPattern(("127.0.0.1", 7000), "keyPattern", 5)
87
82
```
83
+ keyPattern should be a plain string or a RedisRegex.
84
+ keysRDD is a RDD holds all the keys of keyPattern of the redis server.
85
+ keysRDD is divided into 5(default 3) partitions by hash slots.
86
+
87
+ Using Redis' Key/Values
88
+ ```
89
+ import com.redislabs.provider.redis._
90
+ val keysRDD = sc.fromRedisKeyPattern(("127.0.0.1", 7000), "keyPattern", 5)
91
+ val kvRDD = keysRDD.getKV
92
+ ```
93
+ kvRDD is a RDD holds all the k/v pairs whose k's pattern is keyPattern, and k must be of 'string' type in redis-server.
94
+
95
+ Using Redis' Hash
96
+ ```
97
+ import com.redislabs.provider.redis._
98
+ val keysRDD = sc.fromRedisKeyPattern(("127.0.0.1", 7000), "keyPattern", 5)
99
+ val hashRDD = keysRDD.getHash
100
+ ```
101
+ hashRDD is a RDD holds all the dicts' contents, and the dicts' names must be of keyPattern and exists in the redis-server.
102
+
103
+ Using Redis' ZSet
104
+ ```
105
+ import com.redislabs.provider.redis._
106
+ val keysRDD = sc.fromRedisKeyPattern(("127.0.0.1", 7000), "keyPattern", 5)
107
+ val zsetRDD = keysRDD.getZSet
108
+ ```
109
+ zsetRDD is a RDD holds all the zsets' contents(key, score), and the zsets' names must be of keyPattern and exists in the redis-server.
110
+
111
+ Using Redis' List
112
+ ```
113
+ import com.redislabs.provider.redis._
114
+ val keysRDD = sc.fromRedisKeyPattern(("127.0.0.1", 7000), "keyPattern", 5)
115
+ val listRDD = keysRDD.getList
116
+ ```
117
+ listRDD is a RDD holds all the lists' contents, and the lists' names must be of keyPattern and exists in the redis-server.
118
+
119
+ Using Redis' Set
120
+ ```
121
+ import com.redislabs.provider.redis._
122
+ val keysRDD = sc.fromRedisKeyPattern(("127.0.0.1", 7000), "keyPattern", 5)
123
+ val setRDD = keysRDD.getSet
124
+ ```
125
+ setRDD is a RDD holds all the sets' contents, score), and the sets' names must be of keyPattern and exists in the redis-server.
126
+
127
+ *****
128
+
129
+ To write data to Redis Server, you can use the library by loading the implicits from ` com.redislabs.provider.redis._ ` .
88
130
89
131
In the example we can see how to write to Redis Server.
132
+
133
+ Saving as Redis' Key/Values
134
+ ```
135
+ import com.redislabs.provider.redis._
136
+ val kvRDD = ...
137
+ sc.toRedisKV(kvRDD, ("127.0.0.1", 7000))
138
+ ```
139
+ kvRDD is a RDD holds k/v pairs, we will store all the k/v pairs of kvRDD to the redis-server
140
+
141
+ Saving as Redis' Hash
142
+ ```
143
+ import com.redislabs.provider.redis._
144
+ val hashRDD = ...
145
+ sc.toRedisHASH(hashRDD, hashName, ("127.0.0.1", 7000))
90
146
```
91
- scala> import import com.redislabs.provider.redis._
92
- scala> val keysRDD = sc.fromRedisKeyPattern(("127.0.0.1", 7000), "*", 5)
93
- scala> val kvRDD = keysRDD.getKV
94
- scala> sc.toRedisHASH(kvRDD, "saved_hash", ("127.0.0.1", 7000))
147
+ hashRDD is a RDD holds k/v pairs, we will store all the k/v pairs of hashRDD to a dict named hashName to the redis-server
148
+
149
+ Saving as Redis' ZSet
150
+ ```
151
+ import com.redislabs.provider.redis._
152
+ val zsetRDD = ...
153
+ sc.toRedisZSET(zsetRDD, zsetName, ("127.0.0.1", 7000))
95
154
```
155
+ zsetRDD is a RDD holds k/v pairs, we will store all the k/v pairs of zsetRDD to a zset named zsetName to the redis-server
96
156
157
+ Saving as Redis' List
158
+ ```
159
+ import com.redislabs.provider.redis._
160
+ val listRDD = ...
161
+ sc.toRedisLIST(listRDD, listName, ("127.0.0.1", 7000))
162
+ ```
163
+ listRDD is a RDD holds strings, we will store all the strings of listRDD to a list named listName to the redis-server
164
+
165
+ Saving as Redis' Set
166
+ ```
167
+ import com.redislabs.provider.redis._
168
+ val setRDD = ...
169
+ sc.toRedisSET(setRDD, setName, ("127.0.0.1", 7000))
170
+ ```
171
+ setRDD is a RDD holds strings, we will store all the unique strings of setRDD to a set named setName to the redis-server
0 commit comments