当前位置: 首页>>代码示例>>Python>>正文


Python hiredis.Reader方法代码示例

本文整理汇总了Python中hiredis.Reader方法的典型用法代码示例。如果您正苦于以下问题:Python hiredis.Reader方法的具体用法?Python hiredis.Reader怎么用?Python hiredis.Reader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hiredis的用法示例。


在下文中一共展示了hiredis.Reader方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reconnect_init

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def reconnect_init(self, connection):
        connection.xid = 1
        connection.redis_replyxid = 1
        connection.redis_ping = -1
        connection.redis_pingreply = -1
        connection.redis_bufferedxid = 0
        connection.redis_sendbuffer = []
        connection.redis_sender = False
        write_buffer = []
        if self.usehiredis:
            connection.redis_reader = hiredis.Reader(protocolError = RedisProtocolException, replyError = RedisReplyException)
        else:
            connection.redis_reader = RedisParser()
        if connection.redis_select:
            write_buffer.append(self.format_request(b'SELECT', connection.redis_select))
            connection.xid += 1
        if connection.redis_subscribe:
            if connection.redis_subscribe_keys:
                write_buffer.append(self.format_request(b'SUBSCRIBE', *tuple(connection.redis_subscribe_keys)))
            if connection.redis_subscribe_pkeys:
                write_buffer.append(self.format_request(b'PSUBSCRIBE', *tuple(connection.redis_subscribe_pkeys)))
        connection.scheduler.emergesend(ConnectionWriteEvent(connection, connection.connmark, data=b''.join(write_buffer)))
        await connection.wait_for_send(RedisConnectionStateEvent(RedisConnectionStateEvent.CONNECTION_UP, connection, connection.connmark, self)) 
开发者ID:hubo1016,项目名称:vlcp,代码行数:25,代码来源:redis.py

示例2: __init__

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def __init__(self):
        self.dictionary = dictionary
        self.response = collections.deque()
        self.parser = hiredis.Reader()
        self.transport = None  # type: asyncio.transports.Transport
        self.commands = {
            b"COMMAND": self.command,
            b"SET": self.set,
            b"GET": self.get,
            b"PING": self.ping,
            b"INCR": self.incr,
            b"LPUSH": self.lpush,
            b"RPUSH": self.rpush,
            b"LPOP": self.lpop,
            b"RPOP": self.rpop,
            b"SADD": self.sadd,
            b"HSET": self.hset,
            b"SPOP": self.spop,
            b"LRANGE": self.lrange,
            b"MSET": self.mset,
        } 
开发者ID:boramalper,项目名称:pydis,代码行数:23,代码来源:__main__.py

示例3: on_connect

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def on_connect(self, connection):
        self._sock = connection._sock
        self._socket_timeout = connection.socket_timeout
        kwargs = {
            'protocolError': InvalidResponse,
            'replyError': self.parse_error,
        }

        # hiredis < 0.1.3 doesn't support functions that create exceptions
        if not HIREDIS_SUPPORTS_CALLABLE_ERRORS:
            kwargs['replyError'] = ResponseError

        if connection.encoder.decode_responses:
            kwargs['encoding'] = connection.encoder.encoding
        if HIREDIS_SUPPORTS_ENCODING_ERRORS:
            kwargs['errors'] = connection.encoder.encoding_errors
        self._reader = hiredis.Reader(**kwargs)
        self._next_response = False 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:connection.py

示例4: _connect

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def _connect(self):
        if self._closed:
            raise PyRedisConnError('Connection Gone')
        if self.host:
            sock = self._connect_inet46()
        else:
            sock = self._connect_unix()
        self._sock = sock
        if self._encoding:
            self._reader = Reader(encoding=self._encoding)
        else:
            self._reader = Reader()
        self._authenticate()
        if not self._sentinel:
            self._setdb()
            self._set_read_only()
        self._sock.settimeout(self._read_timeout) 
开发者ID:schlitzered,项目名称:pyredis,代码行数:19,代码来源:connection.py

示例5: __init__

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def __init__(self, host, port, timeout=5):
        self.host = host
        self.port = port
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.reader = hiredis.Reader()
        self.last_raw_message = EMPTY

        self.sock.settimeout(timeout)
        logging.debug('Connect to %s:%d', host, port)
        self._conn() 
开发者ID:projecteru,项目名称:redis-trib.py,代码行数:12,代码来源:connection.py

示例6: _recv

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def _recv(self):
        while True:
            m = self.sock.recv(16384)
            self.last_raw_message += m
            self.reader.feed(m)
            r = self.reader.gets()
            # From hiredis.Reader : https://github.com/redis/hiredis-py#usage
            # > When the buffer does not contain a full reply, gets returns False.
            if r != False:
                return r 
开发者ID:projecteru,项目名称:redis-trib.py,代码行数:12,代码来源:connection.py

示例7: on_connect

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def on_connect(self, connection):
        self._sock = connection._sock
        kwargs = {
            'protocolError': InvalidResponse,
            'replyError': self.parse_error,
        }

        # hiredis < 0.1.3 doesn't support functions that create exceptions
        if not HIREDIS_SUPPORTS_CALLABLE_ERRORS:
            kwargs['replyError'] = ResponseError

        if connection.decode_responses:
            kwargs['encoding'] = connection.encoding
        self._reader = hiredis.Reader(**kwargs)
        self._next_response = False 
开发者ID:leancloud,项目名称:satori,代码行数:17,代码来源:connection.py

示例8: on_connect

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def on_connect(self, connection):
        self._stream = connection._reader
        kwargs = {
            'protocolError': InvalidResponse,
            'replyError': ResponseError,
        }
        if connection.decode_responses:
            kwargs['encoding'] = connection.encoding
        self._reader = hiredis.Reader(**kwargs)
        self._next_response = False 
开发者ID:NoneGG,项目名称:aredis,代码行数:12,代码来源:connection.py

示例9: __init__

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def __init__(self,
                 hosts,
                 on_close=None,
                 io_loop=None,
                 clustering=False,
                 auto_connect=True):
        """Create a new instance of the ``Client`` class.

        :param hosts: A list of host connection values.
        :type hosts: list(dict)
        :param io_loop: Override the current Tornado IOLoop instance
        :type io_loop: tornado.ioloop.IOLoop
        :param method on_close: The method to call if the connection is closed
        :param bool clustering: Toggle the cluster support in the client
        :param bool auto_connect: Toggle the auto-connect on creation feature

        """
        self._buffer = bytes()
        self._busy = locks.Lock()
        self._closing = False
        self._cluster = {}
        self._clustering = clustering
        self._connected = locks.Event()
        self._connect_future = concurrent.Future()
        self._connection = None
        self._discovery = False
        self._hosts = hosts
        self._on_close_callback = on_close
        self._reader = hiredis.Reader()
        self.io_loop = io_loop or ioloop.IOLoop.current()
        if not self._clustering:
            if len(hosts) > 1:
                raise ValueError('Too many hosts for non-clustering mode')
        if auto_connect:
            LOGGER.debug('Auto-connecting')
            self.connect() 
开发者ID:gmr,项目名称:tredis,代码行数:38,代码来源:client.py

示例10: __init__

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def __init__(self):
        self.req_reader = hiredis.Reader()
        self.req_reader.setmaxbuf(0)
        self.resp_reader = hiredis.Reader()
        self.resp_reader.setmaxbuf(0)

        self.commands = []
        self.responses = 0
        self.request_size = 0
        self.response_size = 0 
开发者ID:jplesperance,项目名称:redis-sniffer,代码行数:12,代码来源:sniffer.py

示例11: connect

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def connect(self):
        """Connects the client object to redis.

        It's safe to use this method even if you are already connected.
        Note: this method is useless with autoconnect mode (default).

        Returns:
            a Future object with True as result if the connection was ok.
        """
        if self.is_connected():
            raise tornado.gen.Return(True)
        cb1 = self._read_callback
        cb2 = self._close_callback
        self.__callback_queue = collections.deque()
        self._reply_list = []
        self.__reader = hiredis.Reader(replyError=ClientError)
        kwargs = self.connection_kwargs
        self.__connection = Connection(cb1, cb2, **kwargs)
        connection_status = yield self.__connection.connect()
        if connection_status is not True:
            # nothing left to do here, return
            raise tornado.gen.Return(False)
        if self.password is not None:
            authentication_status = yield self._call('AUTH', self.password)
            if authentication_status != b'OK':
                # incorrect password, return back the result
                LOG.warning("impossible to connect: bad password")
                self.__connection.disconnect()
                raise tornado.gen.Return(False)
        if self.db != 0:
            db_status = yield self._call('SELECT', self.db)
            if db_status != b'OK':
                LOG.warning("can't select db %s", self.db)
                raise tornado.gen.Return(False)
        raise tornado.gen.Return(True) 
开发者ID:thefab,项目名称:tornadis,代码行数:37,代码来源:client.py

示例12: setUp

# 需要导入模块: import hiredis [as 别名]
# 或者: from hiredis import Reader [as 别名]
def setUp(self):
        test_redis_uds_or_raise_skiptest()
        super(AbstractConnectionTestCase, self).setUp()
        self.reader = hiredis.Reader()
        self.reply_queue = tornado.queues.Queue() 
开发者ID:thefab,项目名称:tornadis,代码行数:7,代码来源:test_connection.py


注:本文中的hiredis.Reader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。