zoukankan      html  css  js  c++  java
  • 遍历 redis 数据库

    在redis数据库里存储了一些商品分类和对应商品个数,将其取出存进文件里。

    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.Set;
    
    import redis.clients.jedis.Jedis;
    
    public class readRedis {
        public static void main(String args[]) throws IOException {
            Jedis jedis = new Jedis("127.0.0.1", 6379);
            readallRediskeys(jedis);
        }
        
        public static void readallRediskeys(Jedis jedis) throws IOException {
            Set<?> s = jedis.keys("*");
            Iterator<?> it = s.iterator();
            String FILEPATH = "/home/tqhy/yl/";
            FileWriter writer = new FileWriter(FILEPATH + "category3.txt", true);        
            while(it.hasNext()) {
                String key = (String) it.next();
                String value = jedis.get(key);
                System.out.println(key + ": " + value);
                writer.write(key + ": " + value);
                writer.write(System.getProperty("line.separator"));
            }
            writer.close();
        }
    }

    参考链接:

     https://java-er.com/blog/redis-jedis-java/

  • 相关阅读:
    js中常见事件
    第六周
    石家庄地铁售票系统
    第五周
    第四周
    html总结2
    返回一个整数数组中最大子数组的和(续)
    第九周总结
    团队冲刺第五天-KeepRunningAPP
    团队冲刺第四天-KeepRunningAPP
  • 原文地址:https://www.cnblogs.com/lely/p/10315536.html
Copyright © 2011-2022 走看看