java实现用Redis来存储关注关系
更新时间:2024-07-06 20:52:01 阅读量: 综合文库 文档下载
用Redis来存储关注关系(java实现)
?
Redis Dev redis Java代码 1. 2. 3. //一个接口UserService.java //一个接口的实现UserServiceImpl.java //两个采用Jedis的客户端测试类FollowTestMain.java,IsFollowTestMain.java
Java代码 1. 2. 3. 4. 5. 6. 7. 8. 9. //UserService.java接口如下 package com.redis.test; import java.util.Set; public interface UserService { public void follow(String userId); public void unfollow(String userId); 10. public Set
Java代码 1. 2. 3. 4. 5. 6. 7. 8. 9. //接口实现方法如下: package com.redis.test; import java.util.Set; import redis.clients.jedis.Jedis; public class UserServiceImpl implements UserService { 10. 11. private String userId; 12. private Jedis redisService; 13. 14. public UserServiceImpl(String userId) { 15. this.userId = userId; 16. this.redisService = new Jedis(\); 17. } 18. 19. /** 20. *@description 关注对应用户编号方法实现 21. *@date 2012-4-1 22. *@parameter 23. *@see com.redis.test.UserService#follow(java.lang.String) 24. */ 25. @Override 26. public void follow(String userId) { 27. this.redisService.sadd(\ + this.userId + \,userId); //add 28. this.redisService.sadd(\ + userId + \,this.userId); //add 29. } 30. 31. /** 32. *@description 获取当前用户所有关注对象的用户编号集合 33. *@date 2012-4-1 34. *@parameter 35. *@see com.redis.test.UserService#following() 36. */ 37. @Override 38. public Set
Java代码 1. 2. 3. 4. //两个测试类如下: package com.redis.test; 5. 6. 7. 8. 9. import java.util.Iterator; public class FollowTestMain { //简单测试、没有采用单元测试Junit 10. public static void main(String[] args) { 11. UserService user1 = new UserServiceImpl(\); 12. UserService user2 = new UserServiceImpl(\); 13. UserService user3 = new UserServiceImpl(\); 14. 15. user1.follow(\); 16. user1.follow(\); 17. 18. user2.follow(\); 19. user2.follow(\); 20. 21. user3.follow(\); 22. user3.follow(\); 23. 24. Iterator
49. System.out.println(\); 50. while(it22.hasNext()){ 51. System.out.print(it22.next()+\); //1 3 52. } 53. 54. Iterator
Java代码 1. 2. 3. 4. 5. 6. 7. 8. 9. package com.redis.test; import java.util.Iterator; public class IsFollowTestMain { //简单测试、没有采用单元测试Junit public static void main(String[] args) { UserService user1 = new UserServiceImpl(\); 10. UserService user2 = new UserServiceImpl(\); 11. UserService user3 = new UserServiceImpl(\); 12. user1.follow(\); 13. 14. user2.follow(\); 15. user2.follow(\); 16. 17. user3.follow(\); 18. user3.follow(\); 19. 20. boolean isfollowing = user1.isfollowing(\); 21. System.out.println(\+isfollowing); //true 22. 23. boolean isfollowed = user1.isfollowedBy(\); 24. System.out.println(\+isfollowed); //true 25. 26. Long followingCount = user1.followingCount(); 27. System.out.println(\+followingCount); //1 28. 29. Long followedCount = user2.followerCount(); 30. System.out.println(\+followedCount); //2 31. 32. Iterator
正在阅读:
java实现用Redis来存储关注关系07-06
天津2015年上半年主治医师(计划生育)相关专业知识试题05-05
2016年中学校长培训计划10-28
修改后妇科临时医嘱签字规范的持续质量改进汇总(PDCA) - 图文01-12
大嗓门的老师作文400字06-21
35kV集电线路直埋施工方案01-16
苏教版小学科学四年级上册知识点汇总01-07
基层医院开展护理业务查房体会08-17
10.14李丰老师上海交流会内容整理03-19
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 现用
- 存储
- 关系
- 关注
- Redis
- java
- 中国地质大学资源学院老师联系方式 - 图文
- 工程量清单计价(工程预算毕业论文)
- 托福听力加试完整版
- 刘燕文诉北京大学行政判决书
- 3.4分式方程(第二课时)教学案 人教新课标版
- 上海大学继续教育学院《传统体育养生》平时作业答案
- 日处理小麦400吨专用面粉生产线建设项目建议书
- 中小学德育论文:天生我材必有用--浅谈中学生自信心的培养
- Unity5中文指导手册 - 图文
- 高层写字楼与商业大厦物业管理研讨会会议实录
- 小孔成像实验报告
- 承继传统美德 弘扬民族精神2
- 财务分析试题库汇总
- 2009年福州市中考数学试题及答案
- 内科学测试题及答案
- 某市污水处理厂工程总承包项目施工组织设计
- 一年从2万到30万:一个炒手的成功心得
- 色谱柱使用规程AS11
- 数字电路复习指导-2012
- 许昌人文历史古迹、寺庙汇总