﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34212	Redis cache client uses a read connection for incr operation	Ilari Sahi	Leo Tom	"RedisCacheClient uses a read only connection for the incr operation:
https://github.com/django/django/blob/main/django/core/cache/backends/redis.py#L133

However, it is a write operation, at least according to Amazon ElastiCache Redis server. redis-py raises a ReadOnlyError exception:

{{{
Traceback (most recent call last):
  File ""/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py"", line 55, in inner
    response = get_response(request)
  File ""/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py"", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File ""/usr/local/lib/python3.10/site-packages/django/views/generic/base.py"", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File ""/usr/local/lib/python3.10/site-packages/django/utils/decorators.py"", line 46, in _wrapper
    return bound_method(*args, **kwargs)
  File ""/usr/local/lib/python3.10/site-packages/ratelimit/decorators.py"", line 18, in _wrapped
    ratelimited = is_ratelimited(request=request, group=group, fn=fn,
  File ""/usr/local/lib/python3.10/site-packages/ratelimit/core.py"", line 119, in is_ratelimited
    usage = get_usage(request, group, fn, key, rate, method, increment)
  File ""/usr/local/lib/python3.10/site-packages/ratelimit/core.py"", line 205, in get_usage
    count = cache.incr(cache_key)
  File ""/usr/local/lib/python3.10/site-packages/django/core/cache/backends/redis.py"", line 214, in incr
    return self._cache.incr(key, delta)
  File ""/usr/local/lib/python3.10/site-packages/django/core/cache/backends/redis.py"", line 136, in incr
    return client.incr(key, delta)
  File ""/usr/local/lib/python3.10/site-packages/redis/commands/core.py"", line 1852, in incrby
    return self.execute_command(""INCRBY"", name, amount)
  File ""/usr/local/lib/python3.10/site-packages/redis/client.py"", line 1258, in execute_command
    return conn.retry.call_with_retry(
  File ""/usr/local/lib/python3.10/site-packages/redis/retry.py"", line 46, in call_with_retry
    return do()
  File ""/usr/local/lib/python3.10/site-packages/redis/client.py"", line 1259, in <lambda>
    lambda: self._send_command_parse_response(
  File ""/usr/local/lib/python3.10/site-packages/redis/client.py"", line 1235, in _send_command_parse_response
    return self.parse_response(conn, command_name, **options)
  File ""/usr/local/lib/python3.10/site-packages/redis/client.py"", line 1275, in parse_response
    response = connection.read_response()
  File ""/usr/local/lib/python3.10/site-packages/redis/connection.py"", line 827, in read_response
    raise response

Exception Type: ReadOnlyError at ...
Exception Value: You can't write against a read only replica.
}}}

In incr-function, get_client should be called with write argument as True."	Bug	closed	Core (Cache system)	4.1	Normal	fixed	redis cache incr	Daniyal Abbasi Nick Pope	Ready for checkin	1	0	0	0	1	0
