org.springframework.data.redis.connection.StringRedisConnection Java Examples
The following examples show how to use
org.springframework.data.redis.connection.StringRedisConnection.
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: BusinessService.java From Pixiv-Illustration-Collection-Backend with Apache License 2.0 | 6 votes |
public List<Artist> queryFollowed(int userId, int currIndex, int pageSize) { List<Artist> artists = businessMapper.queryFollowed(userId, currIndex, pageSize); if (artists.size() != 0) { if (AppContext.get() != null && AppContext.get().get(AuthConstant.USER_ID) != null) { int user = (int) AppContext.get().get(AuthConstant.USER_ID); List<Object> isFollowedList; if (user == userId) { isFollowedList = artists.stream().map(e -> true).collect(Collectors.toList()); } else { isFollowedList = stringRedisTemplate.executePipelined((RedisCallback<String>) redisConnection -> { for (Artist artist : artists) { StringRedisConnection stringRedisConnection = (StringRedisConnection) redisConnection; stringRedisConnection.sIsMember(RedisKeyConstant.ARTIST_FOLLOW_REDIS_PRE + artist.getId(), String.valueOf(user)); } return null; }); } for (int i = 0; i < artists.size(); i++) { artistBizService.dealArtist(artists.get(i)); artists.set(i, new ArtistWithIsFollowedInfo(artists.get(i), (Boolean) isFollowedList.get(i))); } } } return artists; }
Example #2
Source File: RedisSmsVerificationCodeMismatchEventHandler.java From daming with Apache License 2.0 | 6 votes |
public void on(SmsVerificationCodeMismatchEvent event) { String key = toKey(event.getMobile(), event.getScope()); List<Object> attempts = redisTemplate.executePipelined((RedisCallback<Long>) connection -> { StringRedisConnection conn = (StringRedisConnection) connection; conn.sAdd(key, event.toString()); long expires = Duration.between(event.getWhen(), event.getExpiresAt()).getSeconds(); conn.expire(key, expires); conn.sCard(key); return null; }); log.debug("Got Redis pipeline {}", attempts.stream().map(Object::toString).collect(joining(DELIMITER))); if (attempts.size() == 3) { if (toAttempts(attempts) >= threshold) { log.info("Too many failure verification attempts for {} {}", event.getMobile(), event.getScope()); remove(key); domainEventPublisher.publish(new TooManyFailureSmsVerificationAttemptsEvent(UUID.randomUUID().toString(), clock.now(), event.getMobile(), event.getScope())); } } }
Example #3
Source File: IllustrationBizService.java From Pixiv-Illustration-Collection-Backend with Apache License 2.0 | 5 votes |
public void dealIsLikedInfoForIllustList(List<Illustration> illustrationList, int userId) { List<Object> isFollowedList = stringRedisTemplate.executePipelined((RedisCallback<String>) redisConnection -> { for (Illustration illustration : illustrationList) { StringRedisConnection stringRedisConnection = (StringRedisConnection) redisConnection; stringRedisConnection.sIsMember(RedisKeyConstant.ARTIST_FOLLOW_REDIS_PRE + illustration.getArtistId(), String.valueOf(userId)); } return null; }); int size = isFollowedList.size(); for (int i = 0; i < size; i++) { IllustrationWithLikeInfo illustrationWithLikeInfo = new IllustrationWithLikeInfo(illustrationList.get(i), true); illustrationWithLikeInfo.setArtistPreView(new ArtistPreViewWithFollowedInfo(illustrationWithLikeInfo.getArtistPreView(), (Boolean) isFollowedList.get(i))); illustrationList.set(i, illustrationWithLikeInfo); } }
Example #4
Source File: CommentService.java From Pixiv-Illustration-Collection-Backend with Apache License 2.0 | 4 votes |
@Cacheable(value = "comments", key = "#appType+#appId") public List<Comment> pullComment(String appType, Integer appId) { List<Comment> comments = queryCommentList(appType, appId); if (comments.size() == 0) { return comments; } List<Comment> result = new ArrayList<>(); Map<Integer, List<Comment>>[] mayByParentId = new Map[]{null}; //拼接是否点赞 List<Object> isLikedList; if (AppContext.get() != null && AppContext.get().get(AuthConstant.USER_ID) != null) { isLikedList = stringRedisTemplate.executePipelined((RedisCallback<String>) redisConnection -> { comments.forEach(e -> { StringRedisConnection stringRedisConnection = (StringRedisConnection) redisConnection; stringRedisConnection.sIsMember(RedisKeyConstant.LIKE_REDIS_PRE + AppContext.get().get(AuthConstant.USER_ID), String.valueOf(e.toStringForQueryLike())); }); return null; }); } else { isLikedList = comments.stream().map(e -> false).collect(Collectors.toList()); } //顶级评论 mayByParentId[0] = comments.stream().collect(Collectors.groupingBy(e -> { //顶级评论引用列表 if (e.getParentId() == 0) { result.add(e); } return e.getParentId(); })); int index = comments.size(); for (int i = 0; i < index; i++) { Comment comment = comments.get(i); comment.setIsLike((Boolean) isLikedList.get(i)); //拼成树形 if (comment.getParentId() == 0) { comment.setSubCommentList(mayByParentId[0] != null ? mayByParentId[0].get(comment.getId()) : null); } } //最新消息逆序 result.sort(Comparator.comparingInt(Comment::getId)); return result; }