import java.util.*; import java.io.*; import redis.clients.jedis.Jedis; class MakeCourse { 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("course.txt")); while(scan.hasNextLine()){ String line = scan.nextLine(); String[] parsed = line.split("\t"); if(parsed.length!=3){ System.out.println("error in line:"+line); } else { String cid = parsed[0]; String title = parsed[1]; String deptid = parsed[2]; String dname = jedis.get("dept:"+deptid+":dname"); System.out.println("cid:"+cid+" title:"+title+" deptid:"+deptid+" dname:"+dname); jedis.rpush("course",cid); jedis.set("course:"+cid+":title",title); jedis.set("course:"+cid+":deptid",deptid); jedis.hset("course:"+cid,"title",title); jedis.hset("course:"+cid,"deptid",deptid); if(dname!=null){ jedis.set("course:"+cid+":dname",dname); jedis.hset("course:"+cid,"dname",dname); } } } } }