在python3 中使用redis存储数据,存进去的是bytes
>>> import redis >>> import time >>> import json >>> pool = redis.ConnectionPool(host=‘localhost‘, port=6379) >>> redis_obj = redis.Redis(connection_pool=pool) >>> redis_obj.set(‘key2‘,str_data) True >>> redis_obj.get(‘key2‘) b‘hello‘ >>> redis_obj.rpush(‘my_test_list_key2‘,json.dumps([{‘k1‘:‘v1‘},time.time()])) 1 >>> get_data_from_redis_key = redis_obj.lrange(‘my_test_list_key2‘,-1,-1)[0] >>> type(get_data_from_redis_key) <class ‘bytes‘>
时间: 2024-11-04 08:05:23