/* This program displays the list of classes taken by each student Note how the keys are constructed. The program starts by retrieving a list of all student ids. Then it uses the ids to construct keys for the next level of searching. "student:"+sid+":major" is a key in the form student:5:major, which is used to retrive the major of student 5 from the database. */ import java.util.*; import java.io.*; import redis.clients.jedis.Jedis; class DisplayStudents { public static void main(String[] args) throws FileNotFoundException { //Connecting to Redis server on localhost Jedis jedis = new Jedis("redis.cs.oberlin.edu"); //check whether server is running or not System.out.println("Server is running: "+jedis.ping()); /* get list of all students */ List allstudents = jedis.lrange("student",0,-1); /* for each student, get a list of sections */ for(String sid : allstudents){ /* get student name and major */ String sname = jedis.get("student:"+sid+":sname"); String major = jedis.get("student:"+sid+":major"); System.out.println(sid+"\t"+sname+"\t"+major); /* get a list of all sections the student is enrolled in */ Set sections = jedis.smembers("student:"+sid+":sections"); if(sections.size()==0){ System.out.println("\tnot registered for any classes"); } else { /* for each section, display details */ for(String sectid : sections){ Map smap = jedis.hgetAll("section:"+sectid); String prof = smap.get("prof"); String title = smap.get("ctitle"); String courseid = smap.get("courseid"); String dname = jedis.get("course:"+courseid+":dname"); System.out.println("\t"+sectid+"\t"+dname+"\t"+title+"\t"+prof); } } System.out.println(); } } }