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

This commit is contained in:
Ed Morley 2016-08-31 18:15:22 +01:00 committed by Tim Graham
parent c8058dc241
commit d8ef5b0e65
4 changed files with 14 additions and 3 deletions

View File

@ -1,6 +1,7 @@
"Memcached cache backend" "Memcached cache backend"
import pickle import pickle
import re
import time import time
import warnings import warnings
@ -15,7 +16,7 @@ class BaseMemcachedCache(BaseCache):
def __init__(self, server, params, library, value_not_found_exception): def __init__(self, server, params, library, value_not_found_exception):
super(BaseMemcachedCache, self).__init__(params) super(BaseMemcachedCache, self).__init__(params)
if isinstance(server, six.string_types): if isinstance(server, six.string_types):
self._servers = server.split(';') self._servers = re.split('[;,]', server)
else: else:
self._servers = server self._servers = server

View File

@ -173,6 +173,10 @@ Cache
control of client behavior. See the :ref:`cache arguments <cache_arguments>` control of client behavior. See the :ref:`cache arguments <cache_arguments>`
documentation for examples. documentation for examples.
* Memcached backends now allow defining multiple servers as a comma-delimited
string in :setting:`LOCATION <CACHES-LOCATION>`, for convenience with
third-party services that use such strings in environment variables.
CSRF CSRF
~~~~ ~~~~

View File

@ -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* 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 cache, without the need to duplicate cache values on each machine. To take
advantage of this feature, include all server addresses in advantage of this feature, include all server addresses in
:setting:`LOCATION <CACHES-LOCATION>`, either separated by semicolons or as :setting:`LOCATION <CACHES-LOCATION>`, either as a semicolon or comma
a list. delimited string, or as a list.
In this example, the cache is shared over Memcached instances running on IP 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:: address 172.19.26.240 and 172.19.26.242, both on port 11211::
@ -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 storage -- but we point this out here because memory-based caching is
particularly temporary. 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:
Database caching Database caching

View File

@ -1160,6 +1160,7 @@ class BaseMemcachedTests(BaseCacheTests):
locations = [ locations = [
['server1.tld', 'server2:11211'], ['server1.tld', 'server2:11211'],
'server1.tld;server2:11211', 'server1.tld;server2:11211',
'server1.tld,server2:11211',
] ]
for location in locations: for location in locations:
params = {'BACKEND': self.base_params['BACKEND'], 'LOCATION': location} params = {'BACKEND': self.base_params['BACKEND'], 'LOCATION': location}