package com.iexecloud.cloud.casemanager;
import redis.clients.jedis.Jedis;
import java.text.SimpleDateFormat;
import java.util.Date;
public class UVDemo {
private Jedis jedis=new Jedis("127.0.0.1");
/**
* 添加一次用户访问记录
* @param userid
*/
public void addaUserAccess(long userid){
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
String today = date.format(new Date());
jedis.sadd("user_access_::"+today,String.valueOf(userid));
}
public Long getUV(){
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
String today = date.format(new Date());
return jedis.scard("user_access_::"+today);
}
public static void main(String[] args) {
UVDemo uvDemo = new UVDemo();
for (int i = 0; i <100 ; i++) {
long userid=i+1;
for (int j = 0; j <10 ; j++) {
uvDemo.addaUserAccess(userid);
}
}
Long uv = uvDemo.getUV();
System.out.println("当日的UV为:"+uv);
}
}
网站每日UV数据指标去重统计