Redis Learning Note (9)-Pipeline/Distributed

Source: Internet
Author: User

Package Cn.com;import Java.util.arrays;import Java.util.list;import redis.clients.jedis.jedis;import Redis.clients.jedis.jedisshardinfo;import Redis.clients.jedis.pipeline;import Redis.clients.jedis.ShardedJedis; Import Redis.clients.jedis.shardedjedispipeline;public class Redis_dispersed {/** * distributed straight along with cadence * */public static void sync             _dispersed () {list<jedisshardinfo> shards = arrays.aslist (new Jedisshardinfo ("localhost", 6379),     New Jedisshardinfo ("localhost", 6380));     Shardedjedis sharding = new Shardedjedis (shards);     Long start = System.currenttimemillis ();     for (int i = 0; i < 100000; i++) {String result = Sharding.set ("userid" + I, "age" + i);     } Long end = System.currenttimemillis ();     System.out.println ("Execution:" + ((End-start)/1000.0) + "seconds"); Sharding.disconnect ();             }/** * Distributed Direct Connect asynchronous call * */public static void shardpipelined () {list<jedisshardinfo> shards = arrays.aslist ( New Jedisshardinfo ("LocaLhost ", 6379), new Jedisshardinfo (" localhost ", 6380));     Shardedjedis sharding = new Shardedjedis (shards);     Shardedjedispipeline pipeline = sharding.pipelined ();     Long start = System.currenttimemillis ();     for (int i = 0; i < i++) {Pipeline.set ("userid" + I, "age" + i);     } list<object> results = Pipeline.syncandreturnall ();     Long end = System.currenttimemillis ();     System.out.println ("Execution Time:" + ((End-start)/1000.0) + "seconds"); Sharding.disconnect (); }/** * Pipeline pipeline mode is to send some column command packages together to the server execution. * While the server will process multiple commands, the processing results of multiple commands will be packaged together and returned to the client * Note: The more commands are packaged, the more memory is consumed by the cache.     So it's not as good as packing the command as much as possible * */public static void Pipeline () {Jedis Jedis = new Jedis ("localhost", 6379);     Pipeline Pipeline = jedis.pipelined ();     Long start = System.currenttimemillis ();     for (int i = 0; i < 100000; i++) {Pipeline.set ("P" + I, "P" + i);     } list<object> results = Pipeline.syncandreturnall ();     Long end = System.currenttimemillis ();System.out.println ("pipelined SET:" + ((End-start)/1000.0) + "seconds");     Jedis.disconnect (); Jedis.close ();}     /** * Call Transaction in pipeline * */public static void Trans_pipeline () {Jedis Jedis = new Jedis ("localhost", 6379);     Long start = System.currenttimemillis ();     Pipeline Pipeline = jedis.pipelined ();     Pipeline.multi ();     for (int i = 0; i < 100000; i++) {Pipeline.set ("" + I, "" + i);     } pipeline.exec ();     list<object> results = Pipeline.syncandreturnall ();     Long end = System.currenttimemillis ();     System.out.println ("pipelined Transaction:" + ((End-start)/1000.0) + "seconds"); Jedis.disconnect (); }public static void Main (String [] args) {shardpipelined ();}}

  

Redis Learning Note (9)-Pipeline/Distributed

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.