Aerospike:zlib/bz2 存储和检索没有工作
Aerospike: zlib/bz2 store and retrieve didnt worked
我正在使用 zlib 压缩一个字符串,然后存储在 Aerospike bin 中。在检索和解压缩时,我得到 "zlib.error: Error -5 while decompressing data: incomplete or truncated stream"
当我比较原始压缩数据和检索压缩数据时,检索到的数据末尾缺少一些东西。
我正在使用 Aerospike 3.7.3 和 python 客户端 2.0.1
请帮忙
谢谢
更新: 尝试使用 bz2。抛出 ValueError:检索和解压缩时找不到流的结尾。看起来 aerospike 正在从 blob 中剥离最后一个字节或其他内容。
更新: 发布代码
import aerospike
import bz2
config = {
'hosts': [
( '127.0.0.1', 3000 )
],
'policies': {
'timeout': 1000 # milliseconds
}
}
client = aerospike.client(config)
client.connect()
content = "An Aerospike Query"
content_bz2 = bz2.compress(content)
key = ('benchmark', 'myset', 55)
#client.put(key, {'bin0':content_bz2})
(key, meta, bins) = client.get(key)
print bz2.decompress(bins['bin0'])
出现以下错误:
Traceback (most recent call last):
File "asread.py", line 22, in <module>
print bz2.decompress(bins['bin0'])
ValueError: couldn't find end of stream
bz.compress
method returns a string, and the client sees that type and tries to convert it to the server's as_str
类型。如果它在意想不到的位置遇到 [=14=]
,它会截断字符串,导致您的错误。
相反,确保将二进制数据转换为 bytearray
, which the client converts to the server's as_bytes
type. On the read operation, bz.decompress
将与 bytearray
数据一起使用并返回原始字符串。
from __future__ import print_function
import aerospike
import bz2
config = {'hosts': [( '33.33.33.91', 3000 )]}
client = aerospike.client(config)
client.connect()
content = "An Aerospike Query"
content_bz2 = bytearray(bz2.compress(content))
key = ('test', 'bytesss', 1)
client.put(key, {'bin0':content_bz2})
(key, meta, bins) = client.get(key)
print(type(bins['bin0']))
bin0 = bz2.decompress(bins['bin0'])
print(type(bin0))
print(bin0)
回馈
<type 'bytearray'>
<type 'str'>
An Aerospike Query
我正在使用 zlib 压缩一个字符串,然后存储在 Aerospike bin 中。在检索和解压缩时,我得到 "zlib.error: Error -5 while decompressing data: incomplete or truncated stream"
当我比较原始压缩数据和检索压缩数据时,检索到的数据末尾缺少一些东西。
我正在使用 Aerospike 3.7.3 和 python 客户端 2.0.1
请帮忙
谢谢
更新: 尝试使用 bz2。抛出 ValueError:检索和解压缩时找不到流的结尾。看起来 aerospike 正在从 blob 中剥离最后一个字节或其他内容。
更新: 发布代码
import aerospike
import bz2
config = {
'hosts': [
( '127.0.0.1', 3000 )
],
'policies': {
'timeout': 1000 # milliseconds
}
}
client = aerospike.client(config)
client.connect()
content = "An Aerospike Query"
content_bz2 = bz2.compress(content)
key = ('benchmark', 'myset', 55)
#client.put(key, {'bin0':content_bz2})
(key, meta, bins) = client.get(key)
print bz2.decompress(bins['bin0'])
出现以下错误:
Traceback (most recent call last):
File "asread.py", line 22, in <module>
print bz2.decompress(bins['bin0'])
ValueError: couldn't find end of stream
bz.compress
method returns a string, and the client sees that type and tries to convert it to the server's as_str
类型。如果它在意想不到的位置遇到 [=14=]
,它会截断字符串,导致您的错误。
相反,确保将二进制数据转换为 bytearray
, which the client converts to the server's as_bytes
type. On the read operation, bz.decompress
将与 bytearray
数据一起使用并返回原始字符串。
from __future__ import print_function
import aerospike
import bz2
config = {'hosts': [( '33.33.33.91', 3000 )]}
client = aerospike.client(config)
client.connect()
content = "An Aerospike Query"
content_bz2 = bytearray(bz2.compress(content))
key = ('test', 'bytesss', 1)
client.put(key, {'bin0':content_bz2})
(key, meta, bins) = client.get(key)
print(type(bins['bin0']))
bin0 = bz2.decompress(bins['bin0'])
print(type(bin0))
print(bin0)
回馈
<type 'bytearray'>
<type 'str'>
An Aerospike Query