使用 --pipe 批量导入 redis [英] redis bulk import using --pipe
问题描述
我正在尝试使用 --pipe
功能导入一百万行 redis 命令.
I'm trying to import one million lines of redis commands, using the --pipe
feature.
redis_version:2.8.1
cat file.txt |redis-cli --pipe
这会导致以下错误:
从服务器读取错误:对等方重置连接
Error reading from the server: Connection reset by peer
有人知道我做错了什么吗?
Does anyone know what I'm doing wrong?
file.txt
包含,例如,
lpush name joe
lpush name bob
编辑:我现在看到使用管道模式可能有一种特殊的格式(?) - http://redis.io/topics/protocol
edit: I now see there's probably a special format(?) for using pipe mode - http://redis.io/topics/protocol
推荐答案
使用管道模式(又名 大量插入) 您确实必须直接以 Redis 协议 格式提供您的命令.
To use the pipe mode (a.k.a mass insertion) you must indeed provide your commands directly in Redis protocol format.
LPUSH name joe
对应的Redis协议为:
The corresponding Redis protocol for LPUSH name joe
is:
*3
$5
LPUSH
$4
name
$3
joe
或作为带引号的字符串:"*3\r\n$5\r\nLPUSH\r\n$4\r\nname\r\n$3\r\njoe\r\n"
.
Or as a quoted string: "*3\r\n$5\r\nLPUSH\r\n$4\r\nname\r\n$3\r\njoe\r\n"
.
这是您的输入文件必须包含的内容.
This is what your input file must contain.
Redis 文档包含一个 Ruby 示例来帮助您生成协议:请参阅 gen_redis_proto
.
The Redis documentation includes a Ruby sample to help you generate the protocol: see gen_redis_proto
.
这篇关于使用 --pipe 批量导入 redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!