本文整理汇总了Java中org.springframework.data.redis.core.ZSetOperations类的典型用法代码示例。如果您正苦于以下问题:Java ZSetOperations类的具体用法?Java ZSetOperations怎么用?Java ZSetOperations使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZSetOperations类属于org.springframework.data.redis.core包,在下文中一共展示了ZSetOperations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unlike
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.REQUIRED)
public long unlike(Long feedId, Long uid) {
if (feedId == null || uid == null) {
return -1;
}
Like like = likeMapper.getLike(feedId, uid);
if (like == null) {
return -1;
} else {
int deleteResult = likeMapper.delete(like.getId());
if (deleteResult > 0) {
ZSetOperations<String, String> feedLikes = this.template.opsForZSet();
ValueOperations<String, String> feedCount = this.template.opsForValue();
feedLikes.remove(KEY_FEED_LIKE + feedId, Long.toString(uid));
return feedCount.increment(KEY_FEED_LIKE_COUNT + feedId, -1);
}
return -1;
}
}
示例2: likeUserIdsWithFriendsFirst
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
@Override
public List<Long> likeUserIdsWithFriendsFirst(int start, int pageCount, Long feedId, Long uid) {
if (feedId == null) {
return Collections.emptyList();
}
ZSetOperations<String, String> feedLikes = this.template.opsForZSet();
// 求交集,得到好友关系
feedLikes.intersectAndStore(KEY_FEED_LIKE + feedId, UserServiceImpl.KEY_USER_FRIENDS + uid,
KEY_FEED_LIKE_FRIENDS + feedId);
Set<String> friends = feedLikes.range(KEY_FEED_LIKE_FRIENDS + feedId, start, start + pageCount);
if (friends.size() > pageCount) {
return transfer(friends);
} else {
// TODO
// 剩下的,全部遍历,然后检查是否是好友,如果是,直接排除。如果不是,增加到列表中;
// 由于涉及到分页,需要记录上次操作的index
}
return Collections.emptyList();
}
示例3: likeUserIds
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
@Override
public List<Long> likeUserIds(int start, int pageCount, Long feedId) {
if (feedId == null) {
return Collections.emptyList();
}
ZSetOperations<String, String> feedLikes = this.template.opsForZSet();
Set<String> uids = feedLikes.range(KEY_FEED_LIKE + feedId, start, start + pageCount - 1);
return transfer(uids);
}
示例4: sortByScore
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
public void sortByScore(List<Post> posts, Set<ZSetOperations.TypedTuple<Long>> scores) {
Map<Long, Double> map = new HashMap<>();
scores.forEach(s -> map.put(s.getValue(), s.getScore()));
posts.sort((o1, o2) -> {
double diff = map.get(o2.getId()) - map.get(o1.getId());
return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
});
}
示例5: getZSetData
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
protected Map<String, Double> getZSetData(String counterKey) {
Set<ZSetOperations.TypedTuple<String>> rangeWithScore = this.redisTemplate
.boundZSetOps(counterKey).rangeWithScores(0, -1);
Map<String, Double> values = new HashMap<String, Double>(
rangeWithScore.size());
for (Iterator<ZSetOperations.TypedTuple<String>> iterator = rangeWithScore.iterator(); iterator
.hasNext();) {
ZSetOperations.TypedTuple<String> typedTuple = iterator.next();
values.put(typedTuple.getValue(), typedTuple.getScore());
}
return values;
}
示例6: opsForZSet
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
@Override
public ZSetOperations<K, V> opsForZSet() {
try {
return redisTemplate.opsForZSet();
} catch (Exception ex) {
throw new RedisBaoException(ex);
}
}
示例7: getHotPostsOfPage
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
public List<Post> getHotPostsOfPage(int page, int pageSize) throws PageNotFoundException {
Set<ZSetOperations.TypedTuple<Long>> idsWithScore = hotPostService.getPageWithScore(page, pageSize);
return getHotPostsOfPage(page, idsWithScore);
}
示例8: getPageWithScore
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
public Set<ZSetOperations.TypedTuple<Long>> getPageWithScore(int page, int pageSize) {
return hotPosts.reverseRangeWithScores(CACHE_HOT_POSTS, page * pageSize, (page + 1) * pageSize - 1);
}
示例9: getPageWithScoreOfTag
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
public Set<ZSetOperations.TypedTuple<Long>> getPageWithScoreOfTag(Long tagId, int page, int pageSize) {
return hotPosts.reverseRangeWithScores(CACHE_HOT_TAG_POSTS + tagId, page * pageSize, (page + 1) * pageSize - 1);
}
示例10: getPageWithScoreOfTopic
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
public Set<ZSetOperations.TypedTuple<Long>> getPageWithScoreOfTopic(Long topicId, int page, int pageSize) {
return hotPosts.reverseRangeWithScores(CACHE_HOT_TOPIC_POSTS + topicId, page * pageSize, (page + 1) * pageSize - 1);
}
示例11: opsForZSet
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
@Override
public ZSetOperations<K, V> opsForZSet() {
int dbIndex = RedisApplication.redisConnectionDbIndex.get();
return new DefaultZSetOperations<K, V>(this, dbIndex);
}
示例12: zSetOps
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
public ZSetOperations<String, String> zSetOps() {
return redisTemplate.opsForZSet();
}
示例13: setUp
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
redisTemplate = mock(RedisTemplate.class);
zSetOperations = mock(ZSetOperations.class);
super.setUp();
}
示例14: opsForZSet
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
public ZSetOperations<String, Object> opsForZSet(){
return redisTemplate.opsForZSet();
}
示例15: opsForZSet
import org.springframework.data.redis.core.ZSetOperations; //导入依赖的package包/类
ZSetOperations<K, V> opsForZSet();