Student键值对如下:
zhangsan:{ English: 69 Math: 86 Computer: 77 } lisi:{ English: 55 Math: 100 Computer: 88 } |
1. 根据上面给出的键值对,完成如下操作:
(1)用Redis的哈希结构设计出学生表Student(键值可以用student.zhangsan和student.lisi来表示两个键值属于同一个表);
(2)用hgetall命令分别输出zhangsan和lisi的成绩信息;
(1) 用hget命令查询zhangsan的Computer成绩;
(4)修改lisi的Math成绩,改为95。
2.根据上面已经设计出的学生表Student,用Redis的JAVA客户端编程(jedis),实现如下操作:
(1)添加数据:English:45 Math:89 Computer:100
该数据对应的键值对形式如下:
scofield:{ English: 45 Math: 89 Computer: 100 } |
Jedis jedis=new Jedis("127.0.0.1",6379);
System.out.printf(jedis.ping());
Set<String> keys=jedis.keys("*");
System.out.printf(keys.toString());
Map<String,String> map=new HashMap<String, String>();
map.put("english","45");
map.put("math","89");
map.put("computer","100");
jedis.hmset("student.scofield",map);
System.out.printf(jedis.hget("student.scofield","english"));
(2)获取scofield的English成绩信息
Jedis jedis=new Jedis("127.0.0.1",6379);
System.out.printf(jedis.ping());
Set<String> keys=jedis.keys("*");
System.out.printf(keys.toString());
Map<String,String> map=new HashMap<String, String>();
map.put("english","45");
map.put("math","89");
map.put("computer","100");
jedis.hmset("student.scofield",map);
System.out.printf(jedis.hget("student.scofield","english"));