YouTip LogoYouTip

Redis Pipelining

# Redis Pipelining Redis is a TCP service based on the client-server model and the request/response protocol. This means that typically a request follows these steps: * The client sends a query request to the server and listens on the socket for a response, usually in blocking mode, waiting for the server's reply. * The server processes the command and returns the result to the client. * * * ## Redis Pipelining Redis pipelining allows the client to send multiple requests to the server without waiting for each response; instead, it reads all the replies at once after sending all the commands. ### Example To view Redis pipelining, simply start a Redis instance and run the following command: $(echo -en "PINGrn SET tutorialkey redisrnGET tutorialkeyrnINCR visitorrnINCR visitorrnINCR visitorrn"; sleep 10) | nc localhost 6379+PONG +OK redis :1:2:3 In the above example, we use the **PING** command to check whether the Redis server is available; then we set the value of `tutorialkey` to `redis`, retrieve the value of `tutorialkey`, and increment `visitor` three times. From the returned result, we can see that these commands are submitted to the Redis server in one batch and all responses are read back in one batch. * * * ## Advantages of Pipelining The most significant advantage of pipelining is improved Redis server performance. ### Some Benchmark Data In the following benchmark, we use Redis’s Ruby clientβ€”which supports pipeliningβ€”to measure how much pipelining improves speed. require 'rubygems' require 'redis'def bench(descr) start = Time.now yield puts "#{descr} #{Time.now-start} seconds" enddef without_pipelining r = Redis.new 10000.times { r.ping } enddef with_pipelining r = Redis.new r.pipelined { 10000.times { r.ping } } end bench("without pipelining") { without_pipelining } bench("with pipelining") { with_pipelining } Data collected from running this simple script on a Mac OS X system within a LAN shows that round-trip latency has been significantly reduced when pipelining is enabled. without pipelining 1.18
← Redis PartitioningServer Command Getkeys β†’