说明
配置文件参考:https://blog.csdn.net/qq_38428623/article/details/123217001?utm_source=app&app_version=5.1.1&code=app_1562916241&uLinkId=usr1mkqgl919blen
使用
使用示例:
package com.demo.redis.hyper;
import org.redisson.api.RHyperLogLog;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.List;
@Component
public class RedisHyperLoglog {
@Resource
private RedissonClient redissonClient;
public RHyperLogLog<String> getHyperLogLog(String name) {
RHyperLogLog<String> hyperLogLog = redissonClient.getHyperLogLog(name, StringCodec.INSTANCE);
Assert.notNull(hyperLogLog, "hyperLogLog is null");
return hyperLogLog;
}
public boolean add(String name, String value) {
return this.getHyperLogLog(name).add(value);
}
public boolean addAll(String name, List<String> values) {
return this.getHyperLogLog(name).addAll(values);
}
public long count(String name) {
return this.getHyperLogLog(name).count();
}
public long count(String name, String... otherLog) {
return this.getHyperLogLog(name).countWith(otherLog);
}
}
|