案例实战需求之大数据下的用户画像标签去重
介绍
用户画像 英文为User Profile,是根据用户基本属性、社会属性、行为属性、心理属性等真实信息⽽抽象出的⼀个标签化的、虚拟的⽤户模型。“⽤户画像”的实质是对 “⼈”的数字化。应⽤场景有很多,比如个性化推荐、精准营销、⾦融⻛控、精细化运营等等, 举个例⼦来理解⽤户画像的实际应⽤价值,我们经常⽤⼿机⽹购,淘宝⾥⾯的千⼈千⾯通过“标签 tag”来对⽤户的多维度特征进⾏提炼和标识,那每个⼈的⽤户画像就需要存储,set集合就适合去重⽤户画像不⽌针对某个⼈,也可以某⼀⼈群或⾏业的画像,利⽤redis可以很好的去重
@SpringBootTest
class XdclassRedisApplicationTests {@Autowiredprivate RedisTemplate redisTemplate;@Testpublic void userProfile(){BoundSetOperations operations = redisTemplate.boundSetOps("user:tags:1");operations.add("car","student","rich","dog","guangdong","rich");Set<String> set1 = operations.members();System.out.println(set1);operations.remove("dog");Set<String> set2 = operations.members();System.out.println(set2);}
}
社交应用里面的知识,关注、粉丝、共同好友案例
@SpringBootTest
class XdclassRedisApplicationTests {@Autowiredprivate RedisTemplate redisTemplate;/*** 社交应用*/@Testpublic void testSocial(){BoundSetOperations operationsLW = redisTemplate.boundSetOps("user:lw");operationsLW.add("A","B","C","D","E");System.out.println("老王的粉丝:"+operationsLW.members());BoundSetOperations operationsXD = redisTemplate.boundSetOps("user:xd");operationsXD.add("A","B","F","G","H","K","J","W");System.out.println("小d的粉丝:"+operationsXD.members());//差集Set lwSet = operationsLW.diff("user:xd");System.out.println("老王的专属用户:"+lwSet);//差集Set xdSet = operationsXD.diff("user:lw");System.out.println("小D的专属用户:"+xdSet);//交集Set interSet = operationsLW.intersect("user:xd");System.out.println("同时关注了两个人的用户:"+interSet);//并集Set unionSet = operationsLW.union("user:xd");System.out.println("两个人的并集:"+unionSet);//判断A用户是不是老王的粉丝boolean flag = operationsLW.isMember("A");System.out.println("A用户是不是老王的粉丝:"+flag);}
}