11
11
namespace RedisClient \Command \Traits \Version3x2 ;
12
12
13
13
use RedisClient \Command \Parameter \Parameter ;
14
+ use RedisClient \Command \Response \ResponseParser ;
14
15
15
16
trait GeoCommandsTrait {
16
17
17
18
/**
18
19
* GEOADD key longitude latitude member [longitude latitude member ...]
19
20
* Beta Not yet available in a stable version of Redis. Download unstable if you want to test this command.
20
21
* 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
21
23
*
22
24
* @param $key
23
25
* @param array $members [member => [longitude, latitude]]
@@ -29,9 +31,9 @@ public function geoadd($key, array $members) {
29
31
Parameter::key ($ key )
30
32
];
31
33
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) ;
35
37
}
36
38
return $ this ->returnCommand (['GEOADD ' ], $ params );
37
39
}
@@ -40,6 +42,7 @@ public function geoadd($key, array $members) {
40
42
* GEODIST key member1 member2 [unit]
41
43
* Beta Not yet available in a stable version of Redis. Download unstable if you want to test this command.
42
44
* Time complexity: O(log(N))
45
+ * @link http://redis.io/commands/geodist
43
46
*
44
47
* @param string $key
45
48
* @param string $member1
@@ -64,6 +67,7 @@ public function geodist($key, $member1, $member2, $unit = null) {
64
67
* GEOHASH key member [member ...]
65
68
* Beta Not yet available in a stable version of Redis. Download unstable if you want to test this command.
66
69
* 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
67
71
*
68
72
* @param string $key
69
73
* @param string|string[] $members
@@ -76,4 +80,122 @@ public function geohash($key, $members) {
76
80
Parameter::keys ($ members ),
77
81
]);
78
82
}
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
+ }
79
201
}
0 commit comments