用Jedis操做redis示例一,Key,value HashMap

簡單的key,value形式java

 1 public class RedisDemo 
 2 {
 3     public static void main(String[] args) 
 4     {
 5             
 6         Jedis jedis = new Jedis("127.0.0.1");
 7         jedis.connect();
 8         jedis.set("key", "123");
 9         String value = jedis.get("key");
10         System.out.println(value);
11     }
12 }

 

Value中存放HashMapredis

 1 package com.lltse;
 2 
 3 import java.util.HashMap;
 4 import java.util.List;
 5 import java.util.Map;
 6 
 7 import redis.clients.jedis.Jedis;
 8 
 9 public class RedisHashMap 
10 {
11     public static void main(String[] args) 
12     {
13         Jedis jedis = new Jedis("127.0.0.1");
14         
15         Map<String, String> map = new HashMap<String, String>();
16         map.put("name", "lltse");
17         map.put("password", "123456");
18         map.put("sex", "male");
19         
20         jedis.connect();
21         
22         jedis.hmset("user", map);
23         
24         List<String> list = jedis.hmget("user", "name","password");
25         
26         System.out.println("name=" + list.get(0));
27         System.out.println("password=" + list.get(1));
28     }
29 }
相關文章
相關標籤/搜索