File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,35 @@ public function testKeyLocality() {
93
93
$ this ->checkCommonLocality ();
94
94
}
95
95
96
+ public function customDistributor ($ key )
97
+ {
98
+ $ a = unpack ("N* " , md5 ($ key , true ));;
99
+ global $ newRing ;
100
+ $ pos = $ a [1 ] % count ($ newRing );
101
+
102
+ return $ pos ;
103
+ }
104
+
105
+ public function testKeyDistributor ()
106
+ {
107
+ global $ newRing , $ useIndex ;
108
+ $ this ->ra = new RedisArray ($ newRing , array (
109
+ 'index ' => $ useIndex ,
110
+ 'function ' => 'custom_hash ' ,
111
+ 'distributor ' => array ($ this , "customDistributor " )));
112
+
113
+ // custom key distribution function.
114
+ $ this ->addData ('fb ' .rand ());
115
+
116
+ // check that they're all on the expected node.
117
+ $ lastNode = NULL ;
118
+ foreach ($ this ->data as $ k => $ v ) {
119
+ $ node = $ this ->ra ->_target ($ k );
120
+ $ pos = $ this ->customDistributor ($ k );
121
+ $ this ->assertTrue ($ node === $ newRing [$ pos ]);
122
+ }
123
+ }
124
+
96
125
}
97
126
98
127
class Redis_Rehashing_Test extends TestSuite
You can’t perform that action at this time.
0 commit comments