Sending multiple record with one call using hiredis

Kadir Erdem Demir

I hope this list is right for asking questions about redis client "hiredis" . I want to achieve the same thing which I am doing below with redis client . As can be seen redis send 3 different record with one rpush call .

redis 127.0.0.1:6379> rpush test kemal erdem husyin

(integer) 3
redis 127.0.0.1:6379> lrange test 0 -1
1) "kemal"
2) "erdem"
3) "husyin"

In my project I use hiredis an example :

reply =  (redisReply*)(redisCommand(c, "RPUSH %s %s" , channelName,  message));

But Now I have a big log file which every line is being hold in a buff like char[][]; I need to send each line as different records but also need calling rpush only one time for performance .Would you have a advice for me ?

Didier Spezia

It would be a bad idea to send a unique command to push more than a few thousands of items. It would saturate the communication buffers, and a large command will block all other concurrent commands due to the single-threaded nature of Redis.

I suggest to build your push commands by batch of small packets of n items (n between 10 and 100), and to group your push commands in a pipeline of m commands (m between 10 and 100).

The algorithm would be something like this:

While there are still lines to read:
   New Redis pipeline, i=0
   While there are still lines to read and i<m:
      Read at most n lines
      Build push command for the read lines
      Pipeline push command
      ++i
   Flush Redis pipeline, check return status if needed

It will only generate N / (n*m) roundtrips (N being the number of lines in the input file).

To build commands with arbitrary numbers of parameters, you can use the redisAppendCommandArgv function.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Using multiple mutations in one call

sending multiple images using socket python get sent as one to client

Multiple API Resources in one call using laravel

sending multiple parameters in "withParameters:" call

How to delete record for multiple table in one query using oracle

[hiredis]Multiple hincrbys only return one result(REDIS_REPLY_INTEGER)

Sending variable from one ajax call to the next

Import multiple ids in one record

Stripe API - Retrieve Info On Multiple Charges Using One Call

Angular2 multiple components using one REST call

Inserting multiple documents into mongodb using one call in Meteor

Sending multiple messages to SNS on a single call

Sending multiple parameters to Retrofit Interface call

Sending multiple email using python

Sending Multiple Dictionary Variables as one in Template

Sending out multiple reports as one email in splunk

CMD sending multiple embeds instead of one

Sending multiple DocuSign Template in one email?

Wordpress sending multiple AJAX requests on one click

Sending multiple data in one page Jquery

Hiredis publisher only sending first message in a while loop

How to save one record for multiple department using core data in swift 3

insert multiple checkbox value using jquery and ajax but i only insert one record

'Tagging' a record using multiple criteria

Use one .map call to change values for multiple Series/columns in dataframe using one dictionary

call multiple api in one ajax

sending notification to one user using Channels 2

Combine multiple line record into one line

One record from multiple records in the table