PackageCn.ac.iscas.pebble.dc.redispool;ImportJava.io.File;ImportJava.io.FileOutputStream;Importjava.util.Date;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Set;ImportRedis.clients.jedis.Jedis;ImportRedis.clients.jedis.JedisPool;ImportRedis.clients.jedis.JedisPoolConfig;ImportRedis.clients.jedis.Pipeline;ImportRedis.clients.jedis.Response;ImportCn.ac.iscas.pebble.dc.hdfs.AppendToFile;ImportCN.AC.ISCAS.PEBBLE.DC.TEST.P; Public classRedispoolproxy {PrivateHashmap<string,jedispool> poollist =NewHashmap<string,jedispool>(); Public StaticDate Yes =NULL; Private StaticRedispoolproxy _proxy =NULL; Public Staticredispoolproxy getinstance () {if(NULL==_proxy) {_proxy=NewRedispoolproxy (); } return_proxy; } PublicJedispool getpool (String IP,intPort) {Jedispool Pool= Poollist.get (IP + ":" +port); if(NULL==pool) {jedispoolconfig config=NewJedispoolconfig (); Config.setmaxtotal (p.maxtotal);//Maximum number of connectionsConfig.setmaxidle (P.maxidle);//Maximum number of idle connectionsConfig.setmaxwaitmillis (p.maxwaitmillis);//the maximum number of milliseconds to wait when getting a connectionConfig.settestonborrow (true);//check validity when getting a connection, default falsePool =NewJedispool (config, IP, port,60*1000); Poollist.put (IP+ ":" +port, pool); } returnPool; } Public StaticInteger getdatafromredis (String IP,intPortintDB, String Localfilepath,BooleanDelete) {Jedispool Pool=redispoolproxy.getinstance (). Getpool (Ip,port); intCount = 0; BooleanFlag =true; if(NULL!=pool) {Jedis Redis=NULL; Try{Redis=Pool.getresource (); Pipeline Pipeline=redis.pipelined (); Pipeline.select (DB); Response<Set<String>> response = Pipeline.keys ("*"); Pipeline.sync (); Set<String> keys =Response.get (); if(NULL!=keys) {Pipeline.get (key); Pipeline.del (key); } List<Object> result =Pipeline.syncandreturnall (); for(Object value:result) {if(ValueinstanceofString) {System.out.println (String) value+ "\ n"); Count++; } } }Catch(Exception e) {pool.returnbrokenresource (Redis); E.printstacktrace (); Flag=false; } finally { if(NULL! = Redis &&NULL!=pool) {Pool.returnresource (Redis); } } } returncount; }}
Redis Java API