- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用 redis-py,每当我在缓存中存储列表或字典时,运行 get 函数都会返回一个字符串。如何取回原始数据类型?
cache = redis.StrictRedis(host='localhost', port=6379, decode_responses=True)
cache.set("posts",[["bob","My first post"],["mary","My second post"]])
cache.get("post")
>>>"[["bob","My first post"],["mary","My second post"]]"
这是我必须手动完成的事情吗?
最佳答案
列表的列表是你的问题,因为 Redis 不喜欢嵌套结构。
尝试在存储之前转换为 json 并在访问时转换回来。
您的问题与 how to store a complex object in redis (using redis-py) 非常相似
在第 3 个答案(来自 CivFan)中给出了一个示例,该示例可以非常直接地翻译成您正在尝试做的事情。作为引用,该问题/答案中提供的代码片段:
import json
import redis
r = redis.StrictRedis(host='localhost', port=6379, db=0)
images= [
{'type':'big', 'url':'....'},
{'type':'big', 'url':'....'},
{'type':'big', 'url':'....'},
]
json_images = json.dumps(images)
r.set('images', json_images)
unpacked_images = json.loads(r.get('images'))
images == unpacked_images
在链接的问题中还有一些额外的要点值得一读。
关于Python将redis对象转换为原始数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50998856/
在更大的应用程序的上下文中,我的小程序需要将一些数据打印到 Zebra 或 Dymo(取决于用户安装的内容)标签打印机。 我收到的数据是转义形式,我只需要发送到打印机并让它解释它的数据。 搜索我找到了
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭去年。 Improve th
我正在尝试使用 GetUserMedia() 从用户麦克风录制和保存声音片段和 AudioContext蜜蜂。 我已经能够使用 MediaRecorder 做到这一点API,但不幸的是,Safari/
我想编写一个将十六进制数据转换为音频文件的小型Web应用程序。 音频文件的数据将采用十六进制格式,如下所示: DA1FFFF8B3AEEE2E23BBB9A2221F10400180001EF1C1E
在其中一个 API 中,我收到以下 Json 响应:您可以在此处查看此响应示例 Sample Json resopnse { "histogram" : { "1" : "12
如何在 python 上使用 Resuests 库发布原始数据?我正在尝试登录。 Json 抛出异常 TypeError: set(['"clienteLogin":{"Token":"b94261f
有人告诉我,无论何时使用字节,都应该将变量声明为无符号字符。在 Windows 的数据类型中,BYTE 被声明为 unsigned char。 我的问题: 为什么? Unsigned 是从 0 到 2
如何读取 GPS 原始数据,更具体地说,我需要卫星伪距。此数据不提供 NMEA 格式。 最佳答案 卫星伪距在 official API 中不可用 ,既不通过 GpsStatus.Listener 也不
给定以下 XML: 1424 我正在尝试获取
我使用了以下代码将十进制的 bigint 转换为 bytearray(原始数据),但我得到了错误的结果。 这里有什么错误吗? 我正在 Apple Mac 中尝试此操作(适用于 Iphone 应用程序)
我在 iOS 应用程序中使用 Firebase 登录时遇到了表格 View 问题。该表从子提要加载内容。当我第一次登录时,表加载正常,但如果我注销并再次登录,表会重新加载所有数据,将原始数据添加到表的
我正在使用 Apache BCEL动态创建 java 类,每个类都有自己的关联图像。这些生成的类实现了以下接口(interface): interface ImageOwner { byte[
有没有办法读取 Sim 卡的“原始”数据?类似于如何使用 Pdu 的 SmsMessage 原始数据读取原始数据? 最佳答案 阅读SIM卡相关信息需要TelephonyManager API . Te
有没有办法在命令行 curl 中将数据 POST 或 GET(插入您最喜欢的 HTTP 方法)数据到 URL 并包含在原始发布的数据 header 值中,而不是发出 -H 选项? 例如: $curl
我正在开展一个项目,尝试使用 Myo Gesture Control Armband 识别一些用于康复治疗的 Action /姿势。 . 我有三个问题: EMG Raw Data 返回的最大值和最小值
我有 flv 文件,其中包含带有 aac 原始数据的音频标签。每个音频标签都有一组 aac 原始数据。原始数据有不同的大小。我想通过 RTP 发送。我添加了 13 位大小的 AU header 。它是
我使用制造商提供的库通过 USB 访问相机。我通过结构接收有关图像的信息: typedef struct { /*! Buffer handle which contains new data
我正在从事 BLE 项目,其中录音机硬件连续流式传输数据并发送到 iOS 应用程序。从 iOS 应用程序端,我需要读取传输的数据。 硬件向 iOS 应用程序发送 HEX 数据,我们需要创建 .mp3/
我正在尝试使用 AFNetworking 发出 HTTP PUT 请求以在 CouchDB 服务器中创建附件。服务器需要 HTTP 正文中的 base64 编码字符串。如何在不使用 AFNetwork
我有一些 Graylog2 使用 syslog 输入插件接收的日志。 我需要以我收到的相同格式导出它们,无需任何解析,以便我可以发送给应用程序支持团队。 我已将 INPUT 设置为保留 full_ma
我是一名优秀的程序员,十分优秀!