Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #27152 -- Supported comma delimiter in memcached LOCATION string. #7191

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion django/core/cache/backends/memcached.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"Memcached cache backend"

import pickle
import re
import time
import warnings

Expand All @@ -15,7 +16,7 @@ class BaseMemcachedCache(BaseCache):
def __init__(self, server, params, library, value_not_found_exception):
super(BaseMemcachedCache, self).__init__(params)
if isinstance(server, six.string_types):
self._servers = server.split(';')
self._servers = re.split('[;,]', server)
else:
self._servers = server

Expand Down
4 changes: 4 additions & 0 deletions docs/releases/1.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ Cache
control of client behavior. See the :ref:`cache arguments <cache_arguments>`
documentation for examples.

* For memcached backends, the :setting:`LOCATION <CACHES-LOCATION>` setting now
supports defining multiple servers as a comma-delimited string, for convenience
with third-party services that use such strings in environment variables.

CSRF
~~~~

Expand Down
9 changes: 7 additions & 2 deletions docs/topics/cache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ multiple servers. This means you can run Memcached daemons on multiple
machines, and the program will treat the group of machines as a *single*
cache, without the need to duplicate cache values on each machine. To take
advantage of this feature, include all server addresses in
:setting:`LOCATION <CACHES-LOCATION>`, either separated by semicolons or as
a list.
:setting:`LOCATION <CACHES-LOCATION>`, either as a semicolon or comma
delimited string, or as a list.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include a versionchanged annotation


In this example, the cache is shared over Memcached instances running on IP
address 172.19.26.240 and 172.19.26.242, both on port 11211::
Expand Down Expand Up @@ -168,6 +168,11 @@ permanent storage -- they're all intended to be solutions for caching, not
storage -- but we point this out here because memory-based caching is
particularly temporary.

.. versionchanged:: 1.11

The :setting:`LOCATION <CACHES-LOCATION>` setting now supports defining
multiple servers as a comma-delimited string.

.. _database-caching:

Database caching
Expand Down
11 changes: 11 additions & 0 deletions tests/cache/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,17 @@ def test_incr_decr_timeout(self):

class BaseMemcachedTests(BaseCacheTests):

def test_location_multiple_servers(self):
locations = [
['server1.tld', 'server2:11211'],
'server1.tld;server2:11211',
'server1.tld,server2:11211',
]
for location in locations:
params = {'BACKEND': self.base_params['BACKEND'], 'LOCATION': location}
with self.settings(CACHES={'default': params}):
self.assertEqual(cache._servers, ['server1.tld', 'server2:11211'])

def test_invalid_key_characters(self):
"""
On memcached, we don't introduce a duplicate key validation
Expand Down