本文整理汇总了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))
示例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,
}
示例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
示例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)
示例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()
示例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
示例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
示例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
示例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()
示例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
示例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)
示例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()