Redis Java API

Source: Internet
Author: User

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.