1111namespace RedisClient \Command \Traits \Version3x2 ;
1212
1313use RedisClient \Command \Parameter \Parameter ;
14+ use RedisClient \Command \Response \ResponseParser ;
1415
1516trait GeoCommandsTrait {
1617
1718 /**
1819 * GEOADD key longitude latitude member [longitude latitude member ...]
1920 * Beta Not yet available in a stable version of Redis. Download unstable if you want to test this command.
2021 * Time complexity: O(log(N)) for each item added, where N is the number of elements in the sorted set.
22+ * @link http://redis.io/commands/geoadd
2123 *
2224 * @param $key
2325 * @param array $members [member => [longitude, latitude]]
@@ -29,9 +31,9 @@ public function geoadd($key, array $members) {
2931 Parameter::key ($ key )
3032 ];
3133 foreach ($ members as $ member => $ degrees ) {
32- $ params [] = $ degrees [0 ];
33- $ params [] = $ degrees [1 ];
34- $ params [] = $ member ;
34+ $ params [] = Parameter:: string ( $ degrees [0 ]) ;
35+ $ params [] = Parameter:: string ( $ degrees [1 ]) ;
36+ $ params [] = Parameter:: key ( $ member) ;
3537 }
3638 return $ this ->returnCommand (['GEOADD ' ], $ params );
3739 }
@@ -40,6 +42,7 @@ public function geoadd($key, array $members) {
4042 * GEODIST key member1 member2 [unit]
4143 * Beta Not yet available in a stable version of Redis. Download unstable if you want to test this command.
4244 * Time complexity: O(log(N))
45+ * @link http://redis.io/commands/geodist
4346 *
4447 * @param string $key
4548 * @param string $member1
@@ -64,6 +67,7 @@ public function geodist($key, $member1, $member2, $unit = null) {
6467 * GEOHASH key member [member ...]
6568 * Beta Not yet available in a stable version of Redis. Download unstable if you want to test this command.
6669 * Time complexity: O(log(N)) for each member requested, where N is the number of elements in the sorted set.
70+ * @link http://redis.io/commands/geohash
6771 *
6872 * @param string $key
6973 * @param string|string[] $members
@@ -76,4 +80,122 @@ public function geohash($key, $members) {
7680 Parameter::keys ($ members ),
7781 ]);
7882 }
83+
84+ /**
85+ * GEOPOS key member [member ...]
86+ * Beta Not yet available in a stable version of Redis. Download unstable if you want to test this command.
87+ * Time complexity: O(log(N)) for each member requested, where N is the number of elements in the sorted set.
88+ * @link http://redis.io/commands/geopos
89+ *
90+ * @param string $key
91+ * @param string|string[] $members
92+ * @return string[] The command returns an array where each element is a two elements array
93+ * representing longitude and latitude (x,y) of each member name passed as argument to the command.
94+ * Non existing elements are reported as NULL elements of the array.
95+ */
96+ public function geopos ($ key , $ members ) {
97+ return $ this ->returnCommand (['GEOPOS ' ], [
98+ Parameter::key ($ key ),
99+ Parameter::keys ($ members ),
100+ ]);
101+ }
102+
103+ /**
104+ * GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count]
105+ * Beta Not yet available in a stable version of Redis. Download unstable if you want to test this command.
106+ * Time complexity: O(N+log(M)) where N is the number of elements inside the bounding box of
107+ * the circular area delimited by center and radius and M is the number of items inside the index.
108+ * @link http://redis.io/commands/georadius
109+ *
110+ * @param string $key
111+ * @param string $longitude
112+ * @param string $latitude
113+ * @param string $radius
114+ * @param string $unit
115+ * @param bool|false $withcoord
116+ * @param bool|false $withdist
117+ * @param bool|false $withhash
118+ * @param int|null $count
119+ * @param bool|null $asc (true => ASC, false => DESC)
120+ * @return array
121+ */
122+ public function georadius ($ key , $ longitude , $ latitude , $ radius , $ unit , $ withcoord = false , $ withdist = false , $ withhash = false , $ count = null , $ asc = null ) {
123+ $ params = [
124+ Parameter::key ($ key ),
125+ Parameter::string ($ longitude ),
126+ Parameter::string ($ latitude ),
127+ Parameter::string ($ radius ),
128+ Parameter::geoUnit ($ unit ),
129+ ];
130+ $ parse = false ;
131+ if ($ withcoord ) {
132+ $ params [] = Parameter::string ('WITHCOORD ' );
133+ $ parse = true ;
134+ }
135+ if ($ withdist ) {
136+ $ params [] = Parameter::string ('WITHDIST ' );
137+ $ parse = true ;
138+ }
139+ if ($ withhash ) {
140+ $ params [] = Parameter::string ('WITHHASH ' );
141+ $ parse = true ;
142+ }
143+ if ($ count ) {
144+ $ params [] = Parameter::string ('COUNT ' );
145+ $ params [] = Parameter::integer ($ count );
146+ }
147+ if (isset ($ asc )) {
148+ $ params [] = Parameter::string ((bool ) $ asc ? 'ASC ' : 'DESC ' );
149+ }
150+ return $ this ->returnCommand (['GEORADIUS ' ], $ params , $ parse ? ResponseParser::PARSE_GEO_ARRAY : null );
151+ }
152+
153+
154+ /**
155+ * GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count]
156+ * Beta Not yet available in a stable version of Redis. Download unstable if you want to test this command.
157+ * Time complexity: O(N+log(M)) where N is the number of elements inside the bounding box of
158+ * the circular area delimited by center and radius and M is the number of items inside the index.
159+ * @link http://redis.io/commands/georadiusbymember
160+ *
161+ * @param string $key
162+ * @param string $member
163+ * @param string $radius
164+ * @param string $unit
165+ * @param bool|false $withcoord
166+ * @param bool|false $withdist
167+ * @param bool|false $withhash
168+ * @param int|null $count
169+ * @param bool|null $asc (true => ASC, false => DESC)
170+ * @return array
171+ */
172+ public function georadiusbymember ($ key , $ member , $ radius , $ unit , $ withcoord = false , $ withdist = false , $ withhash = false , $ count = null , $ asc = null ) {
173+ $ params = [
174+ Parameter::key ($ key ),
175+ Parameter::key ($ member ),
176+ Parameter::string ($ radius ),
177+ Parameter::geoUnit ($ unit ),
178+ ];
179+ $ parse = false ;
180+ if ($ withcoord ) {
181+ $ params [] = Parameter::string ('WITHCOORD ' );
182+ $ parse = true ;
183+ }
184+ if ($ withdist ) {
185+ $ params [] = Parameter::string ('WITHDIST ' );
186+ $ parse = true ;
187+ }
188+ if ($ withhash ) {
189+ $ params [] = Parameter::string ('WITHHASH ' );
190+ $ parse = true ;
191+ }
192+ if ($ count ) {
193+ $ params [] = Parameter::string ('COUNT ' );
194+ $ params [] = Parameter::integer ($ count );
195+ }
196+ if (isset ($ asc )) {
197+ $ params [] = Parameter::string ((bool ) $ asc ? 'ASC ' : 'DESC ' );
198+ }
199+ return $ this ->returnCommand (['GEORADIUSBYMEMBER ' ], $ params , $ parse ? ResponseParser::PARSE_GEO_ARRAY : null );
200+ }
79201}
0 commit comments