Shuo
Shuo I'm a DBA(Database Administrator), we can share and discuss MySQL, MongoDB, Redis and other databases here, also including learning Python, Shell, Golang together.

Redis ERR Protocol error: too big inline request

How to repeat?

在使用redis-cli set大key的时候,由于一行太长,报错:

1
2
3
4
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
All data transferred. Waiting for the last reply...
ERR Protocol error: too big inline request
ERR server closed connection

How to fix?

使用其它client, 例如python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# from redis import StrictRedis, ConnectionPool
import redis

def getConnectFromPool(host,port,password=''):
    try:
        pool = redis.ConnectionPool(host=host, port=port, password = password)
        conn = redis.Redis(connection_pool=pool)
    except Exception as e:
        print ("Error:connect to redis %s:%s failed." %(host,port))
        return 0
    return conn

if __name__ == '__main__':
    redis_conn = getConnectFromPool('172.12.1.100', 6379, password="123aaa")
    file = "/home/admin/rediskey"
    keyname = "galaxy_dcaeg325g24t"
    with open(file) as fr:
        rows = fr.readlines()[0]
    
    print(redis_conn.set(keyname, rows))

comments powered by Disqus