实验四 NoMysql和关系数据库操作 Redis篇(3)


实验环境:

1、操作系统:Windows10

2Hadoop版本:3.2.2

5Redis版本:3.2.0

6MongoDB版本:4.4.0

7JDK版本:1.8或以上版本;

8Java IDEidea

(三)Redis数据库操作

Student键值对如下:

zhangsan:

English: 69

Math: 86

Computer: 77

lisi:

English: 55

Math: 100

Computer: 88

1. 根据上面给出的键值对,完成如下操作:

1Redis的哈希结构设计出学生表Student键值可以用student.zhangsan和student.lisi来表示两个键值属于同一个表);

HMSET Student.zhangsan English 69 Math 86 Computer 77   
HMSET Student.lisi English 55 Math 100 Computer 88

(2)hgetall命令分别输出zhangsanlisi的成绩信息

hgetall Student.zhangsan

hgetall Student.lisi

(3)hget命令查询zhangsan的Computer成绩

HGET Student.zhangsan Computer

4)修改lisi的Math成绩,95

hset Student.list Math 95
hgetall Student.list

2.根据上面已经设计出的学生表Student,RedisJAVA客户端编程(jedis),实现如下操作:

1)添加数据:English:45  Math:89 Computer:100

该数据对应的键值对形式如下:

scofield:

English: 45

Math: 89

Computer: 100

(2)获取scofieldEnglish成绩信息

Jedis jedis = new Jedis("localhost");
    Map map = new HashMap<>();
    map.put("English","45");
    map.put("Math","89");
    map.put("Computer","100");
    String string= jedis.hmset("Student.scofield",map);
    System.out.println(string);
    Map map2=jedis.hgetAll("Student.scofield");
    System.out.println(map2.toString());
    String string2=jedis.hget("Student.scofield","English");
    System.out.println(string2);

相关