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;

</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
    context </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> ClassPathXmlApplicationContext("spring-monkey.xml", "spring-redis-cluster.xml"<span style="color: rgba(0, 0, 0, 1)">);
    RedisService redisService </span>= context.getBean("redisServiceImpl", RedisService.<span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)">);

    </span><span style="color: rgba(0, 0, 255, 1)">int</span> pageNum = 2; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">当前页面</span>
    <span style="color: rgba(0, 0, 255, 1)">int</span> pageSize = 5; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">每页大小</span>
    <span style="color: rgba(0, 0, 255, 1)">int</span> start = pageSize * (pageNum - 1); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 因为redis中list元素位置基数是0</span>
    <span style="color: rgba(0, 0, 255, 1)">int</span> end = start + pageSize - 1<span style="color: rgba(0, 0, 0, 1)">;
    
    </span><span style="color: rgba(0, 0, 255, 1)">long</span> total = redisService.listSize("userList"<span style="color: rgba(0, 0, 0, 1)">);
    List</span>&lt;String&gt; dataList = redisService.range("userList"<span style="color: rgba(0, 0, 0, 1)">, start, end);
    Page page </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> PageImpl(dataList, <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> PageRequestWrapper(pageNum, pageSize), total);
    
    System.out.println(JavaJsonConvert.java2Json(page));
}

}