django-redis Error 111 connecting to 127.0.0.1:6379.

在 setting.py 中设置完了 django-redis 之后,在 view.py 中使用出现 error:

Error 111 connecting to 127.0.0.1:6379.

-> 参考

出现这个问题是因为服务器中的 redis sercive 没找到或者没开启

如果没安装服务器的话,安装 redis-server

Ubuntu: sudo apt-get install redis-server
sudo yum install redis
(venv) [root@localhost venv]# yum -y install redis
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                           | 3.8 kB  00:00:00
 * base: mirrors.aliyun.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
 
......

Installed:
  redis.x86_64 0:3.2.12-2.el7

Dependency Installed:
  jemalloc.x86_64 0:3.6.0-1.el7

Complete!

安装完之后记得打开 redis 服务

(venv) [root@localhost venv]# systemctl start redis
Redirecting to /bin/systemctl start redis.service

最后,记得设置开机启动,不然下次一重启就会报错

systemctl enable redis

查看是否重启

(venv) [hugin@localhost hugin]$ systemctl status redis
â— redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Mon 2019-07-22 14:49:40 CST; 2min 53s ago
 Main PID: 3738 (redis-server)
   CGroup: /system.slice/redis.service
           └─3738 /usr/bin/redis-server 127.0.0.1:6379

Jul 22 14:49:39 localhost.localdomain systemd[1]: Starting Redis persistent key-value database...
Jul 22 14:49:40 localhost.localdomain systemd[1]: Started Redis persistent key-value database.

Loaded 所在行 显示 enables 即表示开机启动设置成功

转载于:https://www.cnblogs.com/JanSN/p/11097008.html

你可能感兴趣的:(django-redis Error 111 connecting to 127.0.0.1:6379.)