Question

when run the following code, it has error,

expect to get the saved symbolic matrix from redis as a list and use a forloop to print it

it has error

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 

Code:

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
Was it helpful?

Solution

Use r_server.smembers instead of r_server.get

matrixset = r_server.smembers('matrix1')
for x in matrixset:
    print x
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top