- 概述
Jedis是redis官方推荐的用于访问Java客户端,在https://github.com/xetorthio/jedis下载最新的jedis。
- 访问redis
public class RedisDemo {2、在value中存放HashMap
public static void main(String[] args) {
Jedis jedis = new Jedis("127.0.0.1");
jedis.connect();
jedis.set("key", "123");
String value = jedis.get("key");
System.out.println(value);
}
}
package com.nomouse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import redis.clients.jedis.Jedis;
public class RedisHashMap {
public static void main(String[] args) {
Jedis jedis = new Jedis("127.0.0.1");
Map<String, String> map = new HashMap<String, String>();
map.put("name", "nomouse");
map.put("password", "123456");
map.put("sex", "male");
jedis.connect();
jedis.hmset("user", map);
List<String> list = jedis.hmget("user", "name","password");
System.out.println("name=" + list.get(0));
System.out.println("password=" + list.get(1));
}
}