Closed SrujithPoondla closed 6 years ago
I am using redis-py-cluster and then i am executing Matrix commands after loading the ml module. But Matrix add operation is throwing an exception.
import numpy as np
from rediscluster import StrictRedisCluster
startup_nodes = [{"host": "127.0.0.1", "port": "30002"}]
db = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
d = np.random.randn(300,300)
p = d.shape
d = d.flatten()
d = d.tolist()
d.insert(0,p[0])
d.insert(0,p[1])
# print(d)
db.execute_command('ML.MATRIX.SET','a', *d)
u = np.random.randn(300,300)
p = u.shape
d = u.flatten()
d = d.tolist()
d.insert(0,p[0])
d.insert(0,p[1])
db.execute_command('ML.MATRIX.SET','b', *d)
db.execute_command('ML.MATRIX.ADD','a','b','a')
Output:
---------------------------------------------------------------------------
ResponseError Traceback (most recent call last)
<ipython-input-45-a2879839ad57> in <module>()
7 db.execute_command('ML.MATRIX.SET','b', *d)
8 db.execute_command('ML.MATRIX.GET','b')
----> 9 db.execute_command('ML.MATRIX.ADD','a','b','a')
10 # db.execute_command('ML.MATRIX.GET','a')
/usr/local/lib/python3.6/site-packages/rediscluster/utils.py in inner(*args, **kwargs)
99 for _ in range(0, 3):
100 try:
--> 101 return func(*args, **kwargs)
102 except ClusterDownError:
103 # Try again with the new cluster setup. All other errors
/usr/local/lib/python3.6/site-packages/rediscluster/client.py in execute_command(self, *args, **kwargs)
355
356 r.send_command(*args)
--> 357 return self.parse_response(r, command, **kwargs)
358 except (RedisClusterException, BusyLoadingError):
359 raise
/usr/local/lib/python3.6/site-packages/redis/client.py in parse_response(self, connection, command_name, **options)
678 def parse_response(self, connection, command_name, **options):
679 "Parses a response from the Redis server"
--> 680 response = connection.read_response()
681 if command_name in self.response_callbacks:
682 return self.response_callbacks[command_name](response, **options)
/usr/local/lib/python3.6/site-packages/redis/connection.py in read_response(self)
627 raise
628 if isinstance(response, ResponseError):
--> 629 raise response
630 return response
631
ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value
I thought the reason is we might be using one matrix from one node and another from different node. Is there any way to resolve this? Thanks!
I modified the Matrix.add function to my requirements in such a way that both the matrices are stored in the same node. It is working for the above mentioned example.
Are there any redis clients in python that support redis-ml module like Jedis or Jedis-ML in java? Thanks!