• 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));
        }
    }
  • 相关阅读:
    HDU 1423
    POJ 3264
    POJ 3177
    CodeForces 81A
    SPOJ RATING
    ZOJ 2588
    POJ 1523
    POJ 3667
    递归
    数据结构
  • 原文地址:https://www.cnblogs.com/linjiqin/p/7615419.html
Copyright © 2020-2023  润新知