Solution for: data in redis cannot be accessed after the python redis module is connected

created at 07-24-2021 views: 6

Problem background

Use redis to restore the data of dump.rdb successfully, use redis-cli test to see if the data is restored successfully, the results are as follows:

redis-cli

127.0.0.1:6379>KYES *

1) "a"
2) "b"
3) "c"
4) "d"
5) "e"

Use the redis module to access the redis data and find that none of the data can be obtained. The relevant code is as follows:

import redis
conn = redis.Redis() 
print conn.keys()

idea

Use the command netstat -tunlp to get redis information in linux, and find that the redis process is different from the normal process.

0 0.0.0.0:6379            0.0.0.0:*               LISTEN      3845/redis-server *

# Normal process
:::6379            0.0.0.0:*               LISTEN      3845/redis-server *

Solution

Modify the redis connection method

import redis
conn = redis.Redis(host='0.0.0.0', port=6379) 
print conn.keys()


['a',
 'b',
]
created at:07-24-2021
edited at: 07-24-2021: