3030
3131import static io .github .dengliming .redismodule .redisbloom .protocol .Keywords .COMPRESSION ;
3232import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_ADD ;
33+ import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_BYRANK ;
34+ import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_BYREVRANK ;
3335import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_CDF ;
3436import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_CREATE ;
3537import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_INFO ;
3638import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_MAX ;
3739import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_MERGE ;
3840import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_MIN ;
3941import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_QUANTILE ;
42+ import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_RANK ;
4043import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_RESET ;
44+ import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_REVRANK ;
45+ import static io .github .dengliming .redismodule .redisbloom .protocol .RedisCommands .TDIGEST_TRIMMED_MEAN ;
4146
4247public class TDigest extends RedissonObject {
4348
@@ -151,13 +156,7 @@ public List<Double> getQuantile(double... quantiles) {
151156
152157 public RFuture <List <Double >> getQuantileAsync (double ... quantiles ) {
153158 RAssert .notEmpty (quantiles , "quantiles must not be empty" );
154-
155- List <Object > params = new ArrayList <>(quantiles .length + 1 );
156- params .add (getName ());
157- for (double quantile : quantiles ) {
158- params .add (quantile );
159- }
160- return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_QUANTILE , params .toArray ());
159+ return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_QUANTILE , buildParamsWithDoubleValues (quantiles ));
161160 }
162161
163162 /**
@@ -174,12 +173,7 @@ public List<Double> getCdf(double... values) {
174173
175174 public RFuture <List <Double >> getCdfAsync (double ... values ) {
176175 RAssert .notEmpty (values , "values must not be empty" );
177- List <Object > params = new ArrayList <>(values .length + 1 );
178- params .add (getName ());
179- for (double value : values ) {
180- params .add (value );
181- }
182- return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_CDF , params .toArray ());
176+ return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_CDF , buildParamsWithDoubleValues (values ));
183177 }
184178
185179 /**
@@ -209,4 +203,99 @@ public TDigestInfo getInfo() {
209203 public RFuture <TDigestInfo > getInfoAsync () {
210204 return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_INFO , getName ());
211205 }
206+
207+ /**
208+ * TDIGEST.RANK key value [value ...]
209+ *
210+ * @since Bloom 2.4.0
211+ * @return An array of results populated with rank_1, rank_2, ..., rank_N.
212+ */
213+ public List <Integer > rank (double ... values ) {
214+ return get (rankAsync (values ));
215+ }
216+
217+ public RFuture <List <Integer >> rankAsync (double ... values ) {
218+ RAssert .notEmpty (values , "values must not be empty" );
219+ return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_RANK , buildParamsWithDoubleValues (values ));
220+ }
221+
222+ /**
223+ * TDIGEST.REVRANK key value [value ...]
224+ *
225+ * @since Bloom 2.4.0
226+ * @return An array of results populated with rank_1, rank_2, ..., rank_N.
227+ */
228+ public List <Integer > revRank (double ... values ) {
229+ return get (revRankAsync (values ));
230+ }
231+
232+ public RFuture <List <Integer >> revRankAsync (double ... values ) {
233+ RAssert .notEmpty (values , "values must not be empty" );
234+ return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_REVRANK , buildParamsWithDoubleValues (values ));
235+ }
236+
237+ /**
238+ * TDIGEST.BYRANK key rank [rank ...]
239+ *
240+ * @since Bloom 2.4.0
241+ * @return An array of results populated with rank_1, rank_2, ..., rank_N.
242+ */
243+ public List <Double > byRank (int ... ranks ) {
244+ return get (byRankAsync (ranks ));
245+ }
246+
247+ public RFuture <List <Double >> byRankAsync (int ... ranks ) {
248+ RAssert .notEmpty (ranks , "ranks must not be empty" );
249+ return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_BYRANK , buildParamsWithIntValues (ranks ));
250+ }
251+
252+ /**
253+ * TDIGEST.BYREVRANK key reverse_rank [reverse_rank ...]
254+ *
255+ * @since Bloom 2.4.0
256+ * @return An array of results populated with rank_1, rank_2, ..., rank_N.
257+ */
258+ public List <Double > byRevRank (int ... reverseRanks ) {
259+ return get (byRevRankAsync (reverseRanks ));
260+ }
261+
262+ public RFuture <List <Double >> byRevRankAsync (int ... reverseRanks ) {
263+ RAssert .notEmpty (reverseRanks , "reverseRanks must not be empty" );
264+ return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_BYREVRANK , buildParamsWithIntValues (reverseRanks ));
265+ }
266+
267+ /**
268+ * TDIGEST.TRIMMED_MEAN key low_cut_quantile high_cut_quantile
269+ *
270+ * @param lowCutQuantile Exclude observation values lower than this quantile
271+ * @param highCutQuantile Exclude observation values higher than this quantile
272+ * @since Bloom 2.4.0
273+ * @return The estimation of the mean value.
274+ */
275+ public String trimmedMean (double lowCutQuantile , double highCutQuantile ) {
276+ return get (trimmedMeanAsync (lowCutQuantile , highCutQuantile ));
277+ }
278+
279+ public RFuture <String > trimmedMeanAsync (double lowCutQuantile , double highCutQuantile ) {
280+ return commandExecutor .readAsync (getName (), StringCodec .INSTANCE , TDIGEST_TRIMMED_MEAN , getName (),
281+ lowCutQuantile , highCutQuantile );
282+ }
283+
284+ private Object [] buildParamsWithDoubleValues (double ... values ) {
285+ List <Object > params = new ArrayList <>(values .length + 1 );
286+ params .add (getName ());
287+ for (double value : values ) {
288+ params .add (value );
289+ }
290+ return params .toArray ();
291+ }
292+
293+ private Object [] buildParamsWithIntValues (int ... values ) {
294+ List <Object > params = new ArrayList <>(values .length + 1 );
295+ params .add (getName ());
296+ for (int value : values ) {
297+ params .add (value );
298+ }
299+ return params .toArray ();
300+ }
212301}
0 commit comments