英文:
Pushing polar dataframe to redis
问题
将polars dataframe推送到Redis的最佳方法是什么?
目前,我正在尝试读取由write_ipc
返回的_io.BytesIO
缓冲区
redis_instance.set("key", df.write_ipc(file=None, compression="lz4").read())
这似乎不起作用,因为Redis中的键为空。
英文:
What is the best way to push a polars dataframe to redis ?
Currently I am trying to read the _io.BytesIO buffer returned by write_ipc
redis_instance.set("key",df.write_ipc(file = None, compression="lz4").read())
This doesn't seem to work as the key in redis is empty
答案1
得分: 1
write_ipc
返回一个 BytesIO 对象。由于它刚刚写入,位置在流的末尾。BytesIO.read()
将从该位置开始读取,根据你的代码,在定义中它是空的。
你可以使用 getvalue
替代,它将始终读取所有内容。另请参阅此 Stackoverflow 问题关于 BytesIO。或者,你可以通过调用 seek(0)
方法来重置位置,然后再调用 read()
。
英文:
write_ipc
returns a BytesIO object. As it has just written, the position is at the end of the stream. BytesIO.read()
will start reading from the position onwards, which is in your code empty by definition.
You can instead use getvalue
, which will always read all contents. See also this Stackoverflow question on BytesIO Alternatively, you can reset the position by calling the method seek(0)
prior to callling read()
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论