java redis 分页查询数据
Posted Ruthless
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java redis 分页查询数据相关的知识,希望对你有一定的参考价值。
package com.liying.tiger.test; import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import com.liying.monkey.core.util.JavaJsonConvert; import com.liying.monkey.dao.pagination.PageRequestWrapper; import com.liying.monkey.service.api.RedisService; public class RedisServiceTest { private static ApplicationContext context = null; public static void main(String[] args) { context = new ClassPathXmlApplicationContext("spring-monkey.xml", "spring-redis-cluster.xml"); RedisService redisService = context.getBean("redisServiceImpl", RedisService.class); int pageNum = 2; //当前页面 int pageSize = 5; //每页大小 int start = pageSize * (pageNum - 1); // 因为redis中list元素位置基数是0 int end = start + pageSize - 1; long total = redisService.listSize("userList"); List<String> dataList = redisService.range("userList", start, end); Page page = new PageImpl(dataList, new PageRequestWrapper(pageNum, pageSize), total); System.out.println(JavaJsonConvert.java2Json(page)); } }
以上是关于java redis 分页查询数据的主要内容,如果未能解决你的问题,请参考以下文章