pythonic方法处理数据错误:类型为“dict”的输入无效先转换成字节、字符串、int或float?

ujv3wf0j  于 2021-06-09  发布在  Redis
关注(0)|答案(0)|浏览(251)

redis veersion 3.4.1必须使用哈希,不能使用str或其他数据类型数据:

{'_anno': {
    'ctp': 'list',
    'dt': [],
    'ml': 0,
    'na': 'apple',
    'pos': -1,
    'rel': '',
    'st_var': '',
    'tp': 'object'},
'_att': {'_cuser': 'apple card',
         '_last_editor': 'apple card',
         '_protext': 'authorize',
         '_status': 'normal',
         '_theme_id': 'apple card',
         '_view': '12'},
    }

我的代码

pool = redis.ConnectionPool(host=host, port=port)
conn = redis.StrictRedis(connection_pool=pool)

conn.hmset("aaaaaa",data)

上升误差
dataerror:类型为“dict”的输入无效。首先转换为字节、字符串、int或float。
现在代码

pool = redis.ConnectionPool(host=host, port=port)
conn = redis.StrictRedis(connection_pool=pool)
new_data={}
for key,value in data.items():
    new_data[key]=json.dumps(value)
conn.hmset("aaaaaa",new_data)

有没有一种更像Python的方法?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题