本文整理汇总了Python中redis._compat.BytesIO.write方法的典型用法代码示例。如果您正苦于以下问题:Python BytesIO.write方法的具体用法?Python BytesIO.write怎么用?Python BytesIO.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis._compat.BytesIO
的用法示例。
在下文中一共展示了BytesIO.write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: from redis._compat import BytesIO [as 别名]
# 或者: from redis._compat.BytesIO import write [as 别名]
def read(self, length=None):
"""
Read a line from the socket is no length is specified,
otherwise read ``length`` bytes. Always strip away the newlines.
"""
try:
if length is not None:
bytes_left = length + 2 # read the line ending
if length > self.MAX_READ_LENGTH:
# apparently reading more than 1MB or so from a windows
# socket can cause MemoryErrors. See:
# https://github.com/andymccurdy/redis-py/issues/205
# read smaller chunks at a time to work around this
try:
buf = BytesIO()
while bytes_left > 0:
read_len = min(bytes_left, self.MAX_READ_LENGTH)
buf.write(self._fp.read(read_len))
bytes_left -= read_len
buf.seek(0)
return buf.read(length)
finally:
buf.close()
return self._fp.read(bytes_left)[:-2]
# no length, read a full line
return self._fp.readline()[:-2]
except (socket.error, socket.timeout):
e = sys.exc_info()[1]
raise ConnectionError("Error while reading from socket: %s" %
(e.args,))
示例2: pack_command
# 需要导入模块: from redis._compat import BytesIO [as 别名]
# 或者: from redis._compat.BytesIO import write [as 别名]
def pack_command(self, *args):
"Pack a series of arguments into a value Redis command"
output = BytesIO()
output.write(SYM_STAR)
output.write(b(str(len(args))))
output.write(SYM_CRLF)
for enc_value in imap(self.encode, args):
output.write(SYM_DOLLAR)
output.write(b(str(len(enc_value))))
output.write(SYM_CRLF)
output.write(enc_value)
output.write(SYM_CRLF)
return output.getvalue()