com.logicbus.kvalue.xscript.zset.KVZCount Maven / Gradle / Ivy
package com.logicbus.kvalue.xscript.zset;
import java.util.Map;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.logicbus.kvalue.xscript.KVRowOperation;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
import com.logicbus.kvalue.core.KeyValueRow;
import com.logicbus.kvalue.core.SortedSetRow;
/**ZCOUNT key min max
*返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。
*
* @author zhongyi
*
*/
public class KVZCount extends KVRowOperation {
protected String min = "0";
protected String max = "10";
public KVZCount(String tag, Logiclet p) {
super(tag, p);
}
@Override
public void configure(Properties p) {
super.configure(p);
min = PropertiesConstants.getRaw(p, "min", min);
max = PropertiesConstants.getRaw(p, "max", max);
}
@Override
protected void onExecute(KeyValueRow row, Map root, Map current,
LogicletContext ctx, ExecuteWatcher watcher) {
if (row instanceof SortedSetRow) {
SortedSetRow r = (SortedSetRow) row;
ctx.SetValue(id,
String.valueOf(r.count(getDouble(ctx.transform(min), 1d), getDouble(ctx.transform(max), 10d))));
}
}
}