Java Code Examples for redis.clients.jedis.JedisCommands#sadd()
The following examples show how to use
redis.clients.jedis.JedisCommands#sadd() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlackListController.java From feiqu-opensource with Apache License 2.0 | 6 votes |
@PostMapping("/manage/add") @ResponseBody public BaseResult add(String ip){ BaseResult result = new BaseResult(); try { if(!Validator.isIpv4(ip)){ result.setResult(ResultEnum.FAIL); result.setMessage("IP格式不正确!"); return result; } JedisCommands commands = JedisProviderFactory.getJedisCommands(null); commands.sadd(CommonConstant.FQ_BLACK_LIST_REDIS_KEY,ip); } catch (Exception e) { logger.error("",e); }finally { JedisProviderFactory.getJedisProvider(null).release();; } return result; }
Example 2
Source File: CacheManager.java From feiqu-opensource with Apache License 2.0 | 5 votes |
public static void addCollect(String type,Integer uid, Integer thoughtId) { JedisCommands commands = JedisProviderFactory.getJedisCommands(null); try { String key = getCollectKey(type,uid); commands.sadd(key,thoughtId.toString()); commands.expire(key,24*60*60); } finally{ JedisProviderFactory.getJedisProvider(null).release(); } }
Example 3
Source File: CacheManager.java From feiqu-opensource with Apache License 2.0 | 5 votes |
public static void refreshCollect(String type,Integer uid,List<Integer> list) { JedisCommands commands = JedisProviderFactory.getJedisCommands(null); try { String key = getCollectKey(type,uid); for(Integer tid : list){ commands.sadd(key, tid.toString()); } commands.expire(key,24*60*60); } finally{ JedisProviderFactory.getJedisProvider(null).release(); } }
Example 4
Source File: CommonController.java From feiqu-opensource with Apache License 2.0 | 5 votes |
@PostMapping("findActiveUserNames") @ResponseBody public Object findActiveUserNames(){ BaseResult result = new BaseResult(); try {int month = DateUtil.thisMonth()+1; JedisCommands commands = JedisProviderFactory.getJedisCommands(null); String key = "activeUserNames"+month; Set<String> activeNames = commands.smembers(key); if(CollectionUtil.isEmpty(activeNames)){ Set<String> userIds =commands.zrevrange(CommonConstant.FQ_ACTIVE_USER_SORT+month,0,9); if(CollectionUtils.isNotEmpty(userIds)){ List<Integer> userIdList = Lists.newArrayList(); for(String userId : userIds){ userIdList.add(Integer.valueOf(userId)); } FqUserExample example = new FqUserExample(); example.createCriteria().andIdIn(userIdList); List<FqUser> fqUsers = fqUserService.selectByExample(example); List<String> names = fqUsers.stream().map(FqUser::getNickname).collect(Collectors.toList()); result.setData(names); commands.sadd(key,names.toArray(new String[names.size()])); commands.expire(key,7*24*60*60); } }else { result.setData(activeNames); } } catch (Exception e) { logger.error("获取活跃用户信息报错",e); } finally { JedisProviderFactory.getJedisProvider(null).release(); } return result; }
Example 5
Source File: UserController.java From feiqu-opensource with Apache License 2.0 | 4 votes |
@GetMapping("/{uid}/home") public String home(HttpServletRequest request, HttpServletResponse response, @PathVariable Integer uid, @RequestParam(defaultValue = "1") Integer p, String order) { try { FqUserCache user = webUtil.currentUser(request, response); if(user == null){ return login(CommonConstant.DOMAIN_URL+request.getRequestURI(),request); } logger.info("用户:{}登进我的小窝",user.getNickname()); ThoughtWithUser topThought = null; RedisString redisString = new RedisString(CommonConstant.THOUGHT_TOP_LIST); if(org.apache.commons.lang3.StringUtils.isNotEmpty(redisString.get())){ topThought = JSON.parseObject(redisString.get(),ThoughtWithUser.class); }; request.setAttribute("topThought",topThought); if (user.getId().equals(uid)) { PageHelper.startPage(p, 20); ThoughtExample example = new ThoughtExample(); if("zan".equals(order)){ example.setOrderByClause("like_count desc"); }else { example.setOrderByClause("create_time desc"); } example.createCriteria().andDelFlagEqualTo(YesNoEnum.NO.getValue()); List<ThoughtWithUser> thoughts = thoughtService.getThoughtWithUser(example); List<Integer> list = fqCollectService.selectTopicIdsByTypeAndUid(TopicTypeEnum.THOUGHT_TYPE.getValue(),uid); JedisCommands commands = JedisProviderFactory.getJedisCommands(null); if(CollUtil.isNotEmpty(thoughts)){ String key = CacheManager.getCollectKey(TopicTypeEnum.THOUGHT_TYPE.name(),uid); long redisCount = commands.scard(key); if(redisCount == 0){ for(Integer tid : list){ commands.sadd(key, tid.toString()); } commands.expire(key,24*60*60); } for(ThoughtWithUser thoughtWithUser : thoughts){ if(StringUtils.isNotEmpty(thoughtWithUser.getPicList())){ thoughtWithUser.setPictures(Arrays.asList(thoughtWithUser.getPicList().split(","))); } thoughtWithUser.setCollected(commands.sismember(key,thoughtWithUser.getId().toString())); } } PageInfo page = new PageInfo(thoughts); request.setAttribute("thoughtList",thoughts); String followKey = CommonConstant.FQ_FOLLOW_PREFIX+user.getId(); String followStr = commands.get(followKey); int fansCount; int followCount; if(StringUtils.isEmpty(followStr)){ UserFollowExample followExample = new UserFollowExample(); followExample.createCriteria().andFollowedUserIdEqualTo(uid).andDelFlagEqualTo(YesNoEnum.NO.getValue()); fansCount = userFollowService.countByExample(followExample); followExample.clear(); followExample.createCriteria().andFollowerUserIdEqualTo(uid).andDelFlagEqualTo(YesNoEnum.NO.getValue()); followCount = userFollowService.countByExample(followExample); commands.set(followKey,fansCount+"|"+followCount); commands.expire(followKey, 24*60*60); }else { String[] ff = followStr.split("\\|"); fansCount = Integer.valueOf(ff[0]); followCount = Integer.valueOf(ff[1]); } List<SimThoughtDTO> sim7ThoughtDTOS = Lists.newArrayList(); String hotThoughts = commands.get(CommonConstant.SEVEN_DAYS_HOT_THOUGHT_LIST); if(StringUtils.isNotEmpty(hotThoughts)){ sim7ThoughtDTOS = JSON.parseArray(hotThoughts, SimThoughtDTO.class); } request.setAttribute("sevenDaysT",sim7ThoughtDTOS); request.setAttribute("fansCount",fansCount); request.setAttribute("followCount",followCount); request.setAttribute("count",page.getTotal()); request.setAttribute("p",p); request.setAttribute("pageSize",20); request.setAttribute("activeUserList",CommonConstant.FQ_ACTIVE_USER_LIST); }else { return peopleIndex(request,response,uid); } }catch (Exception e){ request.setAttribute(CommonConstant.SYSTEM_ERROR_CODE,"出错了"); return GENERAL_CUSTOM_ERROR_URL; }finally { JedisProviderFactory.getJedisProvider(null).release(); } return "/user/home.html"; }
Example 6
Source File: ThoughtController.java From feiqu-opensource with Apache License 2.0 | 4 votes |
@GetMapping(value = "/my") public String myThoughts(HttpServletRequest request, HttpServletResponse response, @RequestParam(defaultValue = "1") Integer page, Model model){ try { FqUserCache user = webUtil.currentUser(request,response); if(user == null){ return "/login.html"; } PageHelper.startPage(page,20); ThoughtExample example = new ThoughtExample(); example.createCriteria().andUserIdEqualTo(user.getId()).andDelFlagEqualTo(YesNoEnum.NO.getValue()); example.setOrderByClause("create_time desc"); List<ThoughtWithUser> thoughts = thoughtService.getThoughtWithUser(example); List<Integer> list = fqCollectService.selectTopicIdsByTypeAndUid(TopicTypeEnum.THOUGHT_TYPE.getValue(),user.getId()); if(list != null && list.size() > 0){ try { JedisCommands commands = JedisProviderFactory.getJedisCommands(null); String key = CacheManager.getCollectKey(TopicTypeEnum.THOUGHT_TYPE.name(),user.getId()); long redisCount = commands.scard(key); if(redisCount == 0){ for(Integer tid : list){ commands.sadd(key, tid.toString()); } commands.expire(key,24*60*60); } for(ThoughtWithUser thoughtWithUser : thoughts){ thoughtWithUser.setCollected(commands.sismember(key,thoughtWithUser.getId().toString())); } } finally{ JedisProviderFactory.getJedisProvider(null).release(); } } PageInfo pageInfo = new PageInfo(thoughts); model.addAttribute("thoughtList",thoughts); model.addAttribute("count",pageInfo.getTotal()); model.addAttribute("p",page); model.addAttribute("pageSize",20); } catch (Exception e) { logger.error("thought 获取我的想法失败!",e); } return "/thought/thoughts.html"; }