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

CLIENT SETNAME/CLIENT GETNAME #93

Open
offero opened this issue Jan 2, 2016 · 5 comments
Open

CLIENT SETNAME/CLIENT GETNAME #93

offero opened this issue Jan 2, 2016 · 5 comments

Comments

@offero
Copy link

offero commented Jan 2, 2016

I'd like to be able to implement the CLIENT SETNAME and GETNAME operations, but it doesn't work well with a connection pool. What would be the current recommended way to make sure the client connections are named? Is there one?

@offero
Copy link
Author

offero commented Jan 2, 2016

I made a Factory class that inherits from RedisFactory in order to issue the CLIENT SETNAME command in the addConnection function. I'll post a link to a snippet shortly.

@offero
Copy link
Author

offero commented Feb 8, 2016

class ClientNamedRedisFactory(redis.RedisFactory):
    def __init__(self, name, *args, **kwargs):
        redis.RedisFactory.__init__(self, *args, **kwargs)
        self.name = name

    def addConnection(self, conn):
        conn.execute_command("CLIENT", "SETNAME", self.name)
        return redis.RedisFactory.addConnection(self, conn)

def makeConnection(url, name,
                    reconnect = True, charset = "utf-8",
                    isLazy = True, poolsize = 5,
                    replyTimeout = None,
                    convertNumbers = True,
                    connectTimeout = None):
    """A version of txredisapi.makeConnection that uses ClientNameRedisFactory
    instead of txredisapi.RedisFactory.
    """
    host, port, dbid, password = parse_url(url)
    uuid = "%s:%s" % (host, port)
    factory = ClientNameRedisFactory(name, uuid, int(dbid), poolsize, isLazy,
                            redis.ConnectionHandler, charset, password,
                            replyTimeout, convertNumbers)
    factory.continueTrying = reconnect
    for x in xrange(poolsize):
        reactor.connectTCP(host, port, factory, connectTimeout)

    if isLazy:
        return factory.handler
    else:
        return factory.deferred

@fiorix
Copy link
Collaborator

fiorix commented Feb 8, 2016

Can't really see what's going on from my mobile but looks like you want to send a PR?

On Feb 8, 2016, at 4:06 PM, Chris [email protected] wrote:

class ClientNamedRedisFactory(redis.RedisFactory):
def init(self, name, _args, *_kwargs):
redis.RedisFactory.init(self, _args, *_kwargs)
self.name = name

def addConnection(self, conn):
    conn.execute_command("CLIENT", "SETNAME", self.name)
    return redis.RedisFactory.addConnection(self, conn)

def makeConnection(url, name,
reconnect = True, charset = "utf-8",
isLazy = True, poolsize = 5,
replyTimeout = None,
convertNumbers = True,
connectTimeout = None):
"""A version of txredisapi.makeConnection that uses ClientNameRedisFactory
instead of txredisapi.RedisFactory.
"""
host, port, dbid, password = parse_url(url)
uuid = "%s:%s" % (host, port)
factory = ClientNameRedisFactory(name, uuid, int(dbid), poolsize, isLazy,
redis.ConnectionHandler, charset, password,
replyTimeout, convertNumbers)
factory.continueTrying = reconnect
for x in xrange(poolsize):
reactor.connectTCP(host, port, factory, connectTimeout)

if isLazy:
    return factory.handler
else:
    return factory.deferred


Reply to this email directly or view it on GitHub.

@IlyaSkriblovsky
Copy link
Owner

Good idea. I think name might be added as the new optional argument to all [lazy][Sharded]Connection[Pool] functions. Could you please convert it to pull request?

@offero
Copy link
Author

offero commented Feb 9, 2016

Sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants