Permalink
Browse files

Adding patch for IPv6 connection string.

  • Loading branch information...
1 parent ad1c231 commit d997b2e8813172a083947ef08696cd25b7a2ea3a Sean Reifschneider committed Mar 29, 2013
Showing with 17 additions and 0 deletions.
  1. +3 −0 ChangeLog
  2. +14 −0 memcache.py
View
@@ -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
View
@@ -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'^(?P<proto>unix):(?P<path>.*)$', host)
+ if not m:
+ m = re.match(r'^(?P<proto>inet6):'
+ r'\[(?P<host>[^\[\]]+)\](:(?P<port>[0-9]+))?$', host)
if not m:
m = re.match(r'^(?P<proto>inet):'
r'(?P<host>[^:]+)(:(?P<port>[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)

0 comments on commit d997b2e

Please sign in to comment.