Skip to content

Commit 08e1a99

Browse files
committed
add comment for inner logic
1 parent 16d0754 commit 08e1a99

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/main/scala/com/redislabs/provider/redis/RedisConfig.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class RedisConfig(val initialHost: RedisEndpoint) extends Serializable {
113113
* @return a list of RedisNode whose slots union [sPos, ePos] is not null
114114
*/
115115
def getNodesBySlots(sPos: Int, ePos: Int): Array[RedisNode] = {
116+
/* This function judges if [sPos1, ePos1] union [sPos2, ePos2] is not null */
116117
def inter(sPos1: Int, ePos1: Int, sPos2: Int, ePos2: Int) =
117118
if (sPos1 <= sPos2) ePos1 >= sPos2 else ePos2 >= sPos1
118119

@@ -210,6 +211,15 @@ class RedisConfig(val initialHost: RedisEndpoint) extends Serializable {
210211
val slotInfo = slotInfoObj.asInstanceOf[java.util.List[java.lang.Object]]
211212
val sPos = slotInfo.get(0).toString.toInt
212213
val ePos = slotInfo.get(1).toString.toInt
214+
/*
215+
* We will get all the nodes with the slots range [sPos, ePos],
216+
* and create RedisNode for each nodes, the total field of all
217+
* RedisNode are the number of the nodes whose slots range is
218+
* as above, and the idx field is just an index for each node
219+
* which will be used for adding support for slaves and so on.
220+
* And the idx of a master is always 0, we rely on this fact to
221+
* filter master.
222+
*/
213223
(0 until (slotInfo.size - 2)).map(i => {
214224
val node = slotInfo(i + 2).asInstanceOf[java.util.List[java.lang.Object]]
215225
val host = SafeEncoder.encode(node.get(0).asInstanceOf[Array[scala.Byte]])

0 commit comments

Comments
 (0)