Java Code Examples for org.springframework.data.redis.core.HashOperations#entries()
The following examples show how to use
org.springframework.data.redis.core.HashOperations#entries() .
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: RecruitService.java From microservice-recruit with Apache License 2.0 | 6 votes |
/** * @param userId 用户id * @return 职位列表 * @method findByUserId 根据用户id获取已发布的职位 **/ public List<RecruitEntity> getRecruitByUserId(Long userId) { HashOperations<String, String, String> redisHash = redis.opsForHash(); Map<String, String> entries = redisHash.entries(Constant.RECRUIT_REDIS_PREFIX); if (!entries.isEmpty()) { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), RecruitEntity.class)) .filter(e -> e.getHrId().equals(userId)) .collect(Collectors.toList()); } else { List<RecruitEntity> recruitList = recruitRepo.findByHrId(userId); recruitList.forEach(RecruitEntity::deserializeFields); return recruitList; } }
Example 2
Source File: RecruitService.java From microservice-recruit with Apache License 2.0 | 6 votes |
/** * @param userId 用户id * @return 职位列表 * @method findByUserId 根据用户id获取已发布的职位 **/ public List<RecruitEntity> getRecruitByUserId(Long userId) { HashOperations<String, String, String> redisHash = redis.opsForHash(); Map<String, String> entries = redisHash.entries(Constant.RECRUIT_REDIS_PREFIX); if (!entries.isEmpty()) { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), RecruitEntity.class)) .filter(e -> e.getHrId().equals(userId)) .collect(Collectors.toList()); } else { List<RecruitEntity> recruitList = recruitRepo.findByHrId(userId); recruitList.forEach(RecruitEntity::deserializeFields); return recruitList; } }
Example 3
Source File: UserInfoService.java From microservice-recruit with Apache License 2.0 | 5 votes |
/** * 获取投递简历列表 */ public SendInfo getSendList() { HashOperations<String, String, String> redisHash = redis.opsForHash(); Long userId = UserHolder.get().getId(); String sendKey = Constant.getKey(RedisKeys.RESUME_SEND, String.valueOf(userId)); List<SendResume> ret = new ArrayList<>(); Map<String, String> entries = redisHash.entries(sendKey); entries.forEach((k, v) -> ret.add(JSONObject.parseObject(v, SendResume.class))); return new SendInfo(ret); }
Example 4
Source File: AbsRedisDao.java From jeesupport with MIT License | 5 votes |
@Override public Map< ID, T > findHashAll( int _idx, Class< T > _cls ){ try{ database( _idx ); HashOperations< String, ID, T > hash = tpl.opsForHash(); return hash.entries( _cls.getSimpleName() ); }catch ( Exception e ){ log.error( "findHashAll 发生错误:IDX=[" + _idx + "]" + e.toString(), e ); } return new HashMap<>(); }
Example 5
Source File: GroupServiceController.java From sctalk with Apache License 2.0 | 5 votes |
/** * 查询组的属性 * @param groupVersionList * @return 查询结果:群资料(版本) * @since 1.0 */ @GetMapping(path = "/groupPushInfo") @Transactional(readOnly = true) public BaseModel<GroupPushEntity> getGroupPushInfo(@RequestParam("groupId") Long groupId) { BaseModel<GroupPushEntity> groupRes = new BaseModel<>(); IMGroup group = groupRepository.findOne(groupId); if (group != null) { GroupPushEntity groupEntity = new GroupPushEntity(); groupEntity.setId(group.getId()); groupEntity.setAvatar(group.getAvatar()); groupEntity.setCreated(group.getCreated()); groupEntity.setCreatorId(group.getCreator()); groupEntity.setGroupType(group.getType()); groupEntity.setStatus(group.getStatus()); groupEntity.setMainName(group.getName()); groupEntity.setVersion(group.getVersion()); // fillGroupMember String key = RedisKeys.concat(RedisKeys.GROUP_INFO, group.getId()); HashOperations<String, String, String> groupMapOps = redisTemplate.opsForHash(); Map<String, String> groupMemberMap = groupMapOps.entries(key); List<String> userIdList = new ArrayList<>(); if (groupMemberMap != null) { for (String memberId : groupMemberMap.keySet()) { userIdList.add(memberId); } } groupRes.setData(groupEntity); // push shield status List<ShieldStatusEntity> shieldStatusList = groupInternalService.getGroupPush(groupId, userIdList); groupEntity.setUserList(shieldStatusList); } else { groupRes.setCode(1); } return groupRes; }
Example 6
Source File: RedisServiceImpl.java From SpringBoot-Base-System with GNU Lesser General Public License v3.0 | 5 votes |
/** * 获取所有的KV散列值 * * @time 下午9:47:06 * * @version V1.0 * @param key * @return map集合 * @throws Exception */ @Override public Map<Integer, List<String>> hashGetAll(String key) throws Exception { Map<Integer, List<String>> map = null; try { HashOperations<Object, Integer, List<String>> hashOps = redisTemplate.opsForHash(); map = hashOps.entries(key); } catch (Exception e) { log.error("获取map失败错误信息:{}", e.getMessage()); throw new Exception("根据key[" + key + "获取map失败,,error[" + e.getMessage() + "]", e); } return map; }
Example 7
Source File: RecruitService.java From microservice-recruit with Apache License 2.0 | 5 votes |
private List<RecruitEntity> getAllRecruit(String key) { HashOperations<String, String, String> redisHash = redis.opsForHash(); Map<String, String> entries = redisHash.entries(Constant.RECRUIT_REDIS_PREFIX); if (!entries.isEmpty()) { // 获取全量的招聘信息 if (StringUtils.isBlank(key)) { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), RecruitEntity.class)) .collect(Collectors.toList()); } else { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), RecruitEntity.class)) .filter(c -> c.getTitle().contains(key)) .collect(Collectors.toList()); } } List<RecruitEntity> recruitList; if (StringUtils.isBlank(key)) { recruitList = recruitRepo.findAll(); recruitList.forEach(RecruitEntity::deserializeFields); cacheRecruit(recruitList); return recruitList; } // 由于做全量缓存,所以模糊查询时不进行缓存 return recruitRepo.findByTitleIsLike("%" + key + "%"); }
Example 8
Source File: RecruitService.java From microservice-recruit with Apache License 2.0 | 5 votes |
private List<RecruitEntity> findRecruitByTitleIn(List<String> jobList) { HashOperations<String, String, String> redisHash = redis.opsForHash(); Map<String, String> entries = redisHash.entries(Constant.RECRUIT_REDIS_PREFIX); if (!entries.isEmpty()) { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), RecruitEntity.class)) .filter(r -> jobList.contains(r.getTitle())) .collect(Collectors.toList()); } return recruitRepo.findByTitleIn(jobList); }
Example 9
Source File: RecruitService.java From microservice-recruit with Apache License 2.0 | 5 votes |
/** * 获取所有公司 **/ public List<CompanyEntity> getAllCompany(String key) { HashOperations<String, String, String> redisHash = redis.opsForHash(); Map<String, String> entries = redisHash.entries(Constant.COMPANY_REDIS_PREFIX); if (!entries.isEmpty()) { // 获取全量的公司 if (StringUtils.isBlank(key)) { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), CompanyEntity.class)) .collect(Collectors.toList()); } else { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), CompanyEntity.class)) .filter(c -> c.getName().contains(key)) .collect(Collectors.toList()); } } List<CompanyEntity> companyList; if (StringUtils.isBlank(key)) { companyList = companyRepo.findAll(); // 未命中缓存时查询到数据时插入缓存中 cacheCompany(companyList); return companyList; } // 由于做全量缓存,所以模糊查询时不进行缓存 return companyRepo.findByNameIsLike("%" + key + "%"); }
Example 10
Source File: RecruitService.java From microservice-recruit with Apache License 2.0 | 5 votes |
private List<RecruitEntity> getAllRecruit(String key) { HashOperations<String, String, String> redisHash = redis.opsForHash(); Map<String, String> entries = redisHash.entries(Constant.RECRUIT_REDIS_PREFIX); if (!entries.isEmpty()) { // 获取全量的招聘信息 if (StringUtils.isBlank(key)) { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), RecruitEntity.class)) .collect(Collectors.toList()); } else { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), RecruitEntity.class)) .filter(c -> c.getTitle().contains(key)) .collect(Collectors.toList()); } } List<RecruitEntity> recruitList; if (StringUtils.isBlank(key)) { recruitList = recruitRepo.findAll(); recruitList.forEach(RecruitEntity::deserializeFields); cacheRecruit(recruitList); return recruitList; } // 由于做全量缓存,所以模糊查询时不进行缓存 return recruitRepo.findByTitleIsLike("%" + key + "%"); }
Example 11
Source File: UserInfoService.java From microservice-recruit with Apache License 2.0 | 5 votes |
/** * 获取投递简历列表 */ public SendInfo getSendList() { HashOperations<String, String, String> redisHash = redis.opsForHash(); Long userId = UserHolder.get().getId(); String sendKey = Constant.getKey(RedisKeys.RESUME_SEND, String.valueOf(userId)); List<SendResume> ret = new ArrayList<>(); Map<String, String> entries = redisHash.entries(sendKey); entries.forEach((k, v) -> ret.add(JSONObject.parseObject(v, SendResume.class))); return new SendInfo(ret); }
Example 12
Source File: RecruitService.java From microservice-recruit with Apache License 2.0 | 5 votes |
private List<RecruitEntity> findRecruitByTitleIn(List<String> jobList) { HashOperations<String, String, String> redisHash = redis.opsForHash(); Map<String, String> entries = redisHash.entries(Constant.RECRUIT_REDIS_PREFIX); if (!entries.isEmpty()) { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), RecruitEntity.class)) .filter(r -> jobList.contains(r.getTitle())) .collect(Collectors.toList()); } return recruitRepo.findByTitleIn(jobList); }
Example 13
Source File: RecruitService.java From microservice-recruit with Apache License 2.0 | 5 votes |
/** * 获取所有公司 **/ public List<CompanyEntity> getAllCompany(String key) { HashOperations<String, String, String> redisHash = redis.opsForHash(); Map<String, String> entries = redisHash.entries(Constant.COMPANY_REDIS_PREFIX); if (!entries.isEmpty()) { // 获取全量的公司 if (StringUtils.isBlank(key)) { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), CompanyEntity.class)) .collect(Collectors.toList()); } else { return entries .entrySet() .stream() .map(e -> JSONObject.parseObject(e.getValue(), CompanyEntity.class)) .filter(c -> c.getName().contains(key)) .collect(Collectors.toList()); } } List<CompanyEntity> companyList; if (StringUtils.isBlank(key)) { companyList = companyRepo.findAll(); // 未命中缓存时查询到数据时插入缓存中 cacheCompany(companyList); return companyList; } // 由于做全量缓存,所以模糊查询时不进行缓存 return companyRepo.findByNameIsLike("%" + key + "%"); }
Example 14
Source File: RedisServiceImpl.java From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 | 4 votes |
@Override public <K,HK,HV> Map<HK,HV> getMap(final K key) { HashOperations<K, HK, HV> operations = redisTemplate.opsForHash(); return operations.entries(key); }
Example 15
Source File: CacheServiceProvider.java From AsuraFramework with Apache License 2.0 | 4 votes |
@Override public Map<Object, Object> entries(final String key) { final HashOperations<String, Object, Object> operation = redisTemplate.opsForHash(); return operation.entries(getKey(key)); }
Example 16
Source File: MessageServiceImpl.java From sctalk with Apache License 2.0 | 4 votes |
@Override @Transactional public List<UnreadEntity> getUnreadMsgCount(long userId) { List<UnreadEntity> unreadList = new ArrayList<>(); // 查询未读件数 final String userUnreadKey = RedisKeys.concat(RedisKeys.USER_UNREAD, userId); // String unreadKey = "unread_" + userId; HashOperations<String, String, String> hashOptions = redisTemplate.opsForHash(); Map<String, String> mapUnread = hashOptions.entries(userUnreadKey); for (Entry<String, String> uread : mapUnread.entrySet()) { Long fromUserId = Long.valueOf(uread.getKey()); Long relateId = relationShipService.getRelationId(userId, fromUserId, false); // 查询 UnreadEntity unreadEntity = new UnreadEntity(); unreadEntity.setPeerId(fromUserId); unreadEntity.setSessionType(IMBaseDefine.SessionType.SESSION_TYPE_SINGLE_VALUE); unreadEntity.setUnReadCnt(Integer.valueOf(uread.getValue())); IMMessageEntity lastMessage = null; SearchCriteria<IMMessage> messageSearchCriteria = new SearchCriteria<>(); messageSearchCriteria.add(JpaRestrictions.eq("status", DBConstant.DELETE_STATUS_OK, false)); messageSearchCriteria.add(JpaRestrictions.eq("relateId", relateId, false)); Sort sortMessage = new Sort(Sort.Direction.DESC, "created", "id"); Pageable pageable = new PageRequest(0, 1, sortMessage); Page<IMMessage> messageList = messageRepository.findAll(messageSearchCriteria, pageable); if (messageList.hasContent()) { lastMessage = messageList.getContent().get(0); } if (lastMessage != null) { unreadEntity.setLaststMsgId(lastMessage.getMsgId()); unreadEntity.setLaststMsgType(lastMessage.getType()); unreadEntity.setLatestMsgFromUserId(lastMessage.getUserId()); if (lastMessage.getType() == IMBaseDefine.MsgType.MSG_TYPE_SINGLE_TEXT_VALUE) { unreadEntity.setLatestMsgData(lastMessage.getContent()); } else if (lastMessage.getType() == IMBaseDefine.MsgType.MSG_TYPE_SINGLE_AUDIO_VALUE) { // "[语音]"加密后的字符串 byte[] content = SecurityUtils.getInstance().EncryptMsg("[语音]"); unreadEntity.setLatestMsgData(Base64Utils.encodeToString(content)); } else { // 其他 unreadEntity.setLatestMsgData(lastMessage.getContent()); } } unreadList.add(unreadEntity); } return unreadList; }
Example 17
Source File: GroupServiceController.java From sctalk with Apache License 2.0 | 4 votes |
/** * 查询组的属性 * @param groupVersionList * @return 查询结果:群资料(版本) * @since 1.0 */ @GetMapping(path = "/groupInfoList") public BaseModel<List<GroupEntity>> groupInfoList(@RequestParam("groupIdList") List<Long> groupIdList) { if (groupIdList.isEmpty()) { // 避免SQL错误 return BaseModel.ok(new ArrayList<>()); } SearchCriteria<IMGroup> groupSearchCriteria = new SearchCriteria<>(); groupSearchCriteria.add(JpaRestrictions.in("id", groupIdList, false)); Sort sort = new Sort(Sort.Direction.DESC, "updated"); List<IMGroup> groups = groupRepository.findAll(groupSearchCriteria, sort); List<GroupEntity> resData = new ArrayList<>(); for (IMGroup group: groups) { GroupEntity groupEntity = new GroupEntity(); groupEntity.setId(group.getId()); groupEntity.setAvatar(group.getAvatar()); groupEntity.setCreated(group.getCreated()); groupEntity.setCreatorId(group.getCreator()); groupEntity.setGroupType(group.getType()); groupEntity.setStatus(group.getStatus()); groupEntity.setMainName(group.getName()); groupEntity.setVersion(group.getVersion()); resData.add(groupEntity); // fillGroupMember String key = RedisKeys.concat(RedisKeys.GROUP_INFO, group.getId()); HashOperations<String, String, String> groupMapOps = redisTemplate.opsForHash(); Map<String, String> groupMemberMap = groupMapOps.entries(key); List<Long> userIds = new ArrayList<>(); if (groupMemberMap != null) { for (String memberId : groupMemberMap.keySet()) { userIds.add(Long.valueOf(memberId)); } } groupEntity.setUserList(userIds); } BaseModel<List<GroupEntity>> groupRes = new BaseModel<>(); groupRes.setData(resData); return groupRes; }
Example 18
Source File: GroupServiceController.java From sctalk with Apache License 2.0 | 4 votes |
/** * 查询组的属性 * @param groupVersionList * @return 查询结果:群资料 * @since 1.0 */ @PostMapping(path = "/infoList") @Transactional(readOnly = true) public BaseModel<List<GroupEntity>> groupInfoList(@RequestBody Map<String, Integer> groupIdList) { if (groupIdList.isEmpty()) { // 避免SQL错误 return BaseModel.ok(new ArrayList<>()); } // TODO 这里是否需要根据version查数据 List<Long> groupIds = new ArrayList<>(); for (String id: groupIdList.keySet()) { groupIds.add(Long.valueOf(id)); } SearchCriteria<IMGroup> groupSearchCriteria = new SearchCriteria<>(); groupSearchCriteria.add(JpaRestrictions.in("id", groupIds, false)); Sort sort = new Sort(Sort.Direction.DESC, "updated"); List<IMGroup> groups = groupRepository.findAll(groupSearchCriteria, sort); List<GroupEntity> resData = new ArrayList<>(); for (IMGroup group: groups) { int version = groupIdList.get(String.valueOf(group.getId())); if (version < group.getVersion()) { GroupEntity groupEntity = new GroupEntity(); groupEntity.setId(group.getId()); groupEntity.setAvatar(group.getAvatar()); groupEntity.setCreated(group.getCreated()); groupEntity.setCreatorId(group.getCreator()); groupEntity.setGroupType(group.getType()); groupEntity.setStatus(group.getStatus()); groupEntity.setMainName(group.getName()); groupEntity.setVersion(group.getVersion()); resData.add(groupEntity); // fillGroupMember String key = RedisKeys.concat(RedisKeys.GROUP_INFO, group.getId()); HashOperations<String, String, String> groupMapOps = redisTemplate.opsForHash(); Map<String, String> groupMemberMap = groupMapOps.entries(key); List<Long> userIds = new ArrayList<>(); if (groupMemberMap != null) { for (String memberId : groupMemberMap.keySet()) { userIds.add(Long.valueOf(memberId)); } } groupEntity.setUserList(userIds); } } BaseModel<List<GroupEntity>> groupRes = new BaseModel<>(); groupRes.setData(resData); return groupRes; }
Example 19
Source File: RedisService.java From jeecg with Apache License 2.0 | 4 votes |
/** * 从redis中获取map */ public Map<String, Object> getMap(String key){ HashOperations<String, String, Object> hash = redisTemplate.opsForHash(); Map<String,Object> map = hash.entries(key); return map; }