Python使用redis存储对象

2024-10-15 10:41:22

1、先写个测试redis是否正常连接上import rediscache = redis.StrictRedis('172.20.0.227',6379)

Python使用redis存储对象

3、存储Dict对象,取出来为字符串value = {"id":1,"name":"sunxy"}cache.set(key,value,60)cachevalue = cache.get(key)print type(value),type(cachevalue)

Python使用redis存储对象

5、如果不是一个dict,直接是一个对象呢?之前用了django中的对象,来看一下取出来仍然是字符串,如何把对象存进去呢

Python使用redis存储对象

6、eval()只是将结果转换成字典,这个肯定不行,我们应该需要将对象存到redis中。

Python使用redis存储对象Python使用redis存储对象
猜你喜欢