Skip to content

Commit

Permalink
Adding patch for IPv6 connection string.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Reifschneider committed Mar 29, 2013
1 parent ad1c231 commit d997b2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions 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
Expand Down
14 changes: 14 additions & 0 deletions memcache.py
Expand Up @@ -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:
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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)
Expand All @@ -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']
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d997b2e

Please sign in to comment.