Pycharm 连接redis 测试用例
1.redis服务器
启动redis
redis-server
通过客户端关闭保护模式并设置密码
root@Testmysql:~# redis-cli 127.0.0.1:6379> CONFIG SET protected-mode no OK 127.0.0.1:6379> config set requirepass 123456 OK
2.pycharm 连接redis 实例代码
import redis if __name__ == '__main__': try: rs=redis.Redis(host='192.168.58.201',password='123456', port=6379, db=0) except Exception as e: print(e) result = rs.set("name","itcast") print(result)
注意:服务器重启后,配置则失效