Bitmap 的一些案例
161字小于1分钟
2024-08-10
网站用户操作日志
/**
* @ClassName UserOperationDemo
* @Desciption 网站用户操作日志案例
* @Author MaRui
* @Date 2021/8/30 18:09
* @Version 1.0
*/
public class UserOperationLogDemo {
private static Jedis jedis = new Jedis("127.0.0.1", 6379);
public static void main(String[] args) {
UserOperationLogDemo demo = new UserOperationLogDemo();
demo.recordUserOperationLog("操作1", 100);
System.out.println("是否执行过操作:" + demo.hasOperated("操作1", 100));
System.out.println("是否执行过操作:" + demo.hasOperated("操作1", 110));
}
/**
* 记录用户的操作日志
* @param operation
* @param userId
*/
public void recordUserOperationLog(String operation, long userId) {
jedis.setbit("operation::" + operation + ":log", userId, "1");
}
/**
* 判断用户是否执行过某个操作
* @param operation
* @param userId
* @return
*/
public boolean hasOperated(String operation, long userId) {
return jedis.getbit("operation::" + operation + ":log", userId);
}
}