import java.util.*; import java.io.*; import redis.clients.jedis.Jedis; class MakeSection { 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("section.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 sectid = parsed[0]; String courseid = parsed[1]; String prof = parsed[2]; String yroffered = parsed[3]; String ctitle = jedis.get("course:"+courseid+":title"); System.out.println("sectid:"+sectid+" courseid:"+courseid+" prof:"+prof+" yroffered:"+yroffered+" ctitle:"+ctitle); jedis.rpush("section",sectid); jedis.set("section:"+sectid+":courseid",courseid); jedis.set("section:"+sectid+":prof",prof); jedis.set("section:"+sectid+":yroffered",yroffered); jedis.hset("section:"+sectid,"courseid",courseid); jedis.hset("section:"+sectid,"prof",prof); jedis.hset("section:"+sectid,"yroffered",yroffered); jedis.sadd("course:"+courseid+":sections",sectid); jedis.sadd("taughtby:"+prof,sectid); if(ctitle!=null){ jedis.set("section:"+sectid+":ctitle",ctitle); jedis.hset("section:"+sectid,"ctitle",ctitle); jedis.sadd("course:"+courseid+":ctitle",ctitle); } } } } }