①. UV:Unique Visitor,独立访客,一般理解为客户端IP(需要去重考虑)
②. PV:Page View,页面浏览量(不用去重)
③. DAU:日活跃用户量(登录或者使用了某个产品的用户数(去重复登录的用户))
④. MAU:MonthIy Active User,月活跃用户量

全集i={1,2,3,4,5,6,7,8,8,9,9,5}
去掉重复的内容
基数={1,2,3,4,5,6,7,8,9}

List<String> list=new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
list.add("c");
list.add("d");
HashSet<String>hashSet=new HashSet<>(list);
// a,b,c,d
System.out.println(hashSet);
| 命令 | 作用 |
|---|---|
| pfadd key element | 将所有元素添加到key中 |
| pfcount key | 统计key的估算值(不准确) |
| pgmerge new_key key1 key2 | 合并key至新key |



@Service
@Slf4j
public class HyperLogLogService {
@Resource
private RedisTemplate redisTemplate;
/**
* 模拟有用户来点击首页,每个用户就是不同的ip,不重复记录,重复不记录
*/
@PostConstruct
public void init() {
log.info("------模拟后台有用户点击,每个用户ip不同");
//自己启动线程模拟,实际上产不是线程
new Thread(() -> {
String ip = null;
for (int i = 1; i <=200; i++) {
Random random = new Random();
ip = random.nextInt(255)+"."+random.nextInt(255)+"."+random.nextInt(255)+"."+random.nextInt(255);
Long hll = redisTemplate.opsForHyperLogLog().add("hll", ip);
log.info("ip={},该ip访问过的次数={}",ip,hll);
//暂停3秒钟线程
try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
}
},"t1").start();
}
}
@RestController
@Slf4j
public class HyperLogLogController {
@Resource
private RedisTemplate redisTemplate;
@ApiOperation("获得ip去重复后的首页访问量,总数统计")
@RequestMapping(value = "/uv",method = RequestMethod.GET)
public long uv() {
//pfcount
return redisTemplate.opsForHyperLogLog().size("hll");
}
}