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