如何从redis得到同情的对象

时间:2014-03-18 05:32:36

标签: python sympy

运行以下代码时,它有错误,

期望从redis获取保存的符号矩阵 作为列表并使用forloop打印它

它有错误

Traceback (most recent call last): 
  File "testredis.py", line 21, in <module> 
    matrixlist = r_server.get("matrix1") 
  File "build\bdist.win32\egg\redis\client.py", line 705, in get 
  File "build\bdist.win32\egg\redis\client.py", line 461, in execute_command 
  File "build\bdist.win32\egg\redis\client.py", line 471, in parse_response 
  File "build\bdist.win32\egg\redis\connection.py", line 349, in read_response 
redis.exceptions.ResponseError: Operation against a key holding the wrong kind o 
f value 

代码:

import redis 
from sympy import * 
from sympy import Matrix 
from sympy.abc import x, y, z, f, a, b 
from sympy import * 

r_server = redis.Redis("localhost") 

f = Symbol('f') 
x = Symbol('x') 
y = Symbol('y') 
z = Symbol('z') 
varlist = [x,y,z,a,b] 

A = Matrix([[1,0],[0,1]]) 
B = Matrix([[2,0],[0,5]]) 

r_server.sadd("matrix1", A) 
r_server.sadd("matrix1", B) 

matrixlist = r_server.get("matrix1") 
for x in matrixlist
    print x

1 个答案:

答案 0 :(得分:0)

使用r_server.smembers代替r_server.get

matrixset = r_server.smembers('matrix1')
for x in matrixset:
    print x