Servicestack.redis Data manipulation

Source: Internet
Author: User

Simple string type data write. Poco is serialized as a JSON string in Redis.

1      using(varRedis =Newredisclient (connstring))2     {3         if(Redis. Db! =7)4((redisclient) redis). Changedb (7);5  6         varClient = Redis. As<poco>();7        varList =NewList<poco>();8         9        foreach(varKeyinchkeys)Ten        { One list. ADD (client. GetValue (key. ToString (CultureInfo.InvariantCulture )); A        } -  -         returnlist; the}

Redis is known for its speed, which is not the quickest. Because each time a separate Redis access is performed on the top loop, a query is made and a response is returned.

[req1]     [====waiting=====] [                      RESP1] [                            req2]                                 [====waiting=====]                                                  [RESP2]

A faster notation is to use pipeline mode. Pipeline mode does not wait for the result of the last query, and it sends the next query immediately. Whenever a response returns, it response the corresponding callback processing.

Here is the code implementation:

This code is excerpted from the test class of Servicestack.redis

1 [Test]2      Public voidCan_call_single_operation_with_callback_3_times_in_pipeline ()3     {4         varResults =Newlist<Long>();5 Assert.that (Redis.getvalue (Key), is.null);6         using(varPipeline =redis.createpipeline ())7         {8Pipeline. Queuecommand (R =R.incrementvalue (Key), results. ADD);9Pipeline. Queuecommand (R =R.incrementvalue (Key), results. ADD);TenPipeline. Queuecommand (R =R.incrementvalue (Key), results. ADD); One pipeline. Flush (); A         } -  -Assert.that (Redis.getvalue (Key), Is.equalto ("3")); theAssert.that (Results, Is.equivalentto (Newlist<Long> {1,2,3 })); -}

Servicestack.redis Data manipulation

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.