java中使用redis
Redis本质上是一个Key-Value类型的内存数据库。
1)下载redis服务:https://github.com/dmajkic/redis/downloads解压
2)下载jedis(jar):https://github.com/xetorthio/jedis/downloads
3)新建java项目RedisTest及测试类:
[java] view plaincopy
01.import redis.clients.jedis.Jedis;
02.public class JedisDemo {
03. public static void main(String[] args) {
04. Jedis jj = new Jedis("localhost");
05. jj.set("key1", "I am value 1");
06. String ss = jj.get("key1");
07. System.out.println(ss);
08. }
09.}
4)导入jedis-2.0.0.jar
5)运行redis服务redis-server.exe
6)运行JedisDemo项目,输出:I am value 1