Giter VIP home page Giter VIP logo

Comments (5)

offero avatar offero commented on August 30, 2024

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.

from txredisapi.

offero avatar offero commented on August 30, 2024
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

from txredisapi.

fiorix avatar fiorix commented on August 30, 2024

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.

from txredisapi.

IlyaSkriblovsky avatar IlyaSkriblovsky commented on August 30, 2024

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?

from txredisapi.

offero avatar offero commented on August 30, 2024

Sure.

from txredisapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.