import java.util.*; import java.io.*; import redis.clients.jedis.Jedis; class MakeEnroll { public static void main(String[] args) throws FileNotFoundException { // hostname is command-line arg, or localhost by default String hostname = "localhost"; if(args.length>0){ hostname = args[0]; } //Connecting to Redis server on localhost Jedis jedis = new Jedis(hostname); System.out.println("Connection to server sucessfully"); //check whether server is running or not System.out.println("Server is running: "+jedis.ping()); Scanner scan = new Scanner(new File("enroll.txt")); while(scan.hasNextLine()){ String line = scan.nextLine(); String[] parsed = line.split("\t"); if(parsed.length!=4){ System.out.println("error in line:"+line); } else { String eid = parsed[0]; String studentid = parsed[1]; String sectid = parsed[2]; String grade = parsed[3]; String sname = jedis.get("student:"+studentid+":sname"); String ctitle = jedis.get("section:"+sectid+":ctitle"); System.out.println("eid:"+eid+" studentid:"+studentid+" sectid:"+sectid+" grade:"+grade+" sname:"+sname+" ctitle:"+ctitle); jedis.rpush("enroll",eid); jedis.set("enroll:"+eid+":studentid",studentid); jedis.set("enroll:"+eid+":sectid",sectid); jedis.set("enroll:"+eid+":grade",grade); jedis.hset("enroll:"+eid,"studentid",studentid); jedis.hset("enroll:"+eid,"sectid",sectid); jedis.hset("enroll:"+eid,"grade",grade); jedis.sadd("student:"+studentid+":sections",sectid); jedis.sadd("student:"+studentid+":courses",ctitle); jedis.sadd("section:"+sectid+":students",studentid); if(sname!=null){ jedis.set("enroll:"+eid+":sname",sname); jedis.hset("enroll:"+eid,"sname",sname); jedis.sadd("student:"+sname+":sections",sectid); jedis.sadd("section:"+sectid+":studentsbyname",sname); } if(ctitle!=null){ jedis.set("enroll:"+eid+":ctitle",ctitle); jedis.hset("enroll:"+eid,"ctitle",ctitle); jedis.sadd("course:"+ctitle+":students",studentid); } if(ctitle!=null && sname!=null){ jedis.sadd("student:"+sname+":courses",ctitle); } } } } }