今天运行Django项目在redis数据库写入数据时提示如下错误:

ERROR log 228 Internal Server Error: /image_code/cf9ccd75-d274-45c0-94a4-a83c8c189965/
Traceback (most recent call last):
  File "/home/sky/.virtualenvs/dj_xm31/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/sky/.virtualenvs/dj_xm31/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/sky/.virtualenvs/dj_xm31/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/sky/code/djxm31/xm31/dj13/dj13/apps/verifications/views.py", line 14, in image_code
    redis_conn.setex('img_{}'.format(img_id).encode('utf8'),300,text)
  File "/home/sky/.virtualenvs/dj_xm31/lib/python3.6/site-packages/redis/client.py", line 1787, in setex
    return self.execute_command('SETEX', name, time, value)
  File "/home/sky/.virtualenvs/dj_xm31/lib/python3.6/site-packages/redis/client.py", line 878, in execute_command
    return self.parse_response(conn, command_name, **options)
  File "/home/sky/.virtualenvs/dj_xm31/lib/python3.6/site-packages/redis/client.py", line 892, in parse_response
    response = connection.read_response()
  File "/home/sky/.virtualenvs/dj_xm31/lib/python3.6/site-packages/redis/connection.py", line 752, in read_response
    raise response
redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
ERROR basehttp 154 "GET /image_code/cf9ccd75-d274-45c0-94a4-a83c8c189965/ HTTP/1.1" 500 89760

redis数据库写入数据时提示redis.exceptions.ResponseError错误
原因
强制关闭Redis快照导致不能持久化。

解决方案
将stop-writes-on-bgsave-error设置为no

(dj14) sky@py:~$ redis-cli 
127.0.0.1:6379> config set stop-writes-on-bgsave-error no
OK
127.0.0.1:6379>