diff --git a/ChangeLog b/ChangeLog index 256e2a6..6fd6648 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ + * Supports IPv6 connections using: "inet6:[fd00::32:19f7]:11000". + Patch by Romain Courteaud + * Switching over to github for this project: https://github.com/linsomniac diff --git a/memcache.py b/memcache.py index 34a547d..f729c8c 100644 --- a/memcache.py +++ b/memcache.py @@ -264,6 +264,8 @@ def get_stats(self, stat_args = None): if not s.connect(): continue if s.family == socket.AF_INET: name = '%s:%s (%s)' % ( s.ip, s.port, s.weight ) + elif s.family == socket.AF_INET6: + name = '[%s]:%s (%s)' % ( s.ip, s.port, s.weight ) else: name = 'unix:%s (%s)' % ( s.address, s.weight ) if not stat_args: @@ -287,6 +289,8 @@ def get_slabs(self): if not s.connect(): continue if s.family == socket.AF_INET: name = '%s:%s (%s)' % ( s.ip, s.port, s.weight ) + elif s.family == socket.AF_INET6: + name = '[%s]:%s (%s)' % ( s.ip, s.port, s.weight ) else: name = 'unix:%s (%s)' % ( s.address, s.weight ) serverData = {} @@ -1053,6 +1057,9 @@ def __init__(self, host, debug=0, dead_retry=_DEAD_RETRY, # parse the connection string m = re.match(r'^(?Punix):(?P.*)$', host) + if not m: + m = re.match(r'^(?Pinet6):' + r'\[(?P[^\[\]]+)\](:(?P[0-9]+))?$', host) if not m: m = re.match(r'^(?Pinet):' r'(?P[^:]+)(:(?P[0-9]+))?$', host) @@ -1064,6 +1071,11 @@ def __init__(self, host, debug=0, dead_retry=_DEAD_RETRY, if hostData.get('proto') == 'unix': self.family = socket.AF_UNIX self.address = hostData['path'] + elif hostData.get('proto') == 'inet6': + self.family = socket.AF_INET6 + self.ip = hostData['host'] + self.port = int(hostData.get('port') or 11211) + self.address = ( self.ip, self.port ) else: self.family = socket.AF_INET self.ip = hostData['host'] @@ -1187,6 +1199,8 @@ def __str__(self): if self.family == socket.AF_INET: return "inet:%s:%d%s" % (self.address[0], self.address[1], d) + elif self.family == socket.AF_INET6: + return "inet6:[%s]:%d%s" % (self.address[0], self.address[1], d) else: return "unix:%s%s" % (self.address, d)