第一次发帖。看了几天相关的redis 文章和博客,一直没搞懂redis是怎么用做缓存的。在数据库之间例如mysql,本人查询了一些数据,假设本人要做缓存的话是,先查询出来然后放到redis嘛?redis做缓存是把数据通过Key-Value的形式保存在一个实际的文件嘛?。求高手帮忙,先谢谢了。
解决方案
20
public static void Test(){
Jedis dis = new Jedis(“localhost”);
System.out.println(“Connection to server sucessfully”);
System.out.println(“Server is running:”+ dis.ping());
dis.set(“abc”, “value”);
System.out.println(“Stored string in redis:: “+ dis.get(“abc”));
dis.lpush(“key”, “aa”);
dis.lpush(“key”, “bb”);
dis.lpush(“key”, “cc”);
List<String> list = dis.lrange(“key”, 0, 5);
for(int i=0; i<list.size(); i++){
System.out.println(“Stored list in redis:: “+ list.get(i));
}
}
Jedis dis = new Jedis(“localhost”);
System.out.println(“Connection to server sucessfully”);
System.out.println(“Server is running:”+ dis.ping());
dis.set(“abc”, “value”);
System.out.println(“Stored string in redis:: “+ dis.get(“abc”));
dis.lpush(“key”, “aa”);
dis.lpush(“key”, “bb”);
dis.lpush(“key”, “cc”);
List<String> list = dis.lrange(“key”, 0, 5);
for(int i=0; i<list.size(); i++){
System.out.println(“Stored list in redis:: “+ list.get(i));
}
}
20