根据设计出的学生表Student,用Redis的JAVA客户端编程(jedis),实现添加和查询操作:
package test; import java.util.Map; import redis.clients.jedis.Jedis; public class test { /** * @param args */ public static Jedis jedis; public static void main(String[] args) { // TODO Auto-generated method stub jedis = new Jedis("192.168.88.101", 6379); //插入数据 // test1(); //查询数据 test2(); } public static void test1() { // TODO Auto-generated method stub jedis.hset("student.scofield", "English","45"); jedis.hset("student.scofield", "Math","89"); jedis.hset("student.scofield", "Computer","100"); Map<String,String> value = jedis.hgetAll("student.scofield"); for(Map.Entry<String, String> entry:value.entrySet()) { System.out.println(entry.getKey()+":"+entry.getValue()); } } public static void test2() { // TODO Auto-generated method stub String value=jedis.hget("student.scofield", "English"); System.out.println("scofield's English score is: "+value); } }