Redis Mass Insertion

前端 未结 1 1304
别跟我提以往
别跟我提以往 2021-01-18 23:19

I am considering using Redis\' protocol to do mass insertions as described here: http://redis.io/topics/mass-insert Before I get busy write code to handle this I just want

相关标签:
1条回答
  • 2021-01-19 00:18

    I would say you are on the path of premature optimization (which is usually not the best one).

    Any scripting language with a Redis client supporting pipelining should be able to push at least 50K commands/s to the Redis server. The code will be straightforward, with no need to manually encode the Redis protocol. Granted, the massive insert trick is faster, but do you really need it?

    Now, if you still want to stick to massive insert, you need to encode a proper Redis command. The example you provided is wrong for several reasons:

    • the number of arguments is wrong (your example should start by *3)

    • the length of the last argument is wrong (1,2,34 length is 6 bytes not 5).

    • in the SADD command, you need one argument per item of the set (i.e. for Redis 1,2,34 will be a single item, not three).

    The proper command would rather be something like this:

    "*5\r\n$4\r\nSADD\r\n$2\r\n80\r\n$1\r\n1\r\n$1\r\n2\r\n$2\r\n34\r\n"
    

    The Redis protocol is described here: http://redis.io/topics/protocol

    0 讨论(0)
提交回复
热议问题