Open gr33ngiant112 opened 5 years ago
This might be a clue, I just don't know how to interpret it.
I modified the get_job
function to run a raw redis command.
def get_job(self, jobId):
reply = self.execute_command('JSON.GET', jobId)
print(reply)
return reply
When called, throws the error:
return self.response_callbacks[command_name](response, **options)
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: cannot use a string pattern on a bytes-like object
Hello! Your code seems to be good, but the None answer from the client, and the error thrown with your second test confirm that there are no JSON data under that key.
Have you tried the same way as you did with the redis-cli, but with Python ? With the key hard-written in the code ? I'd say that the jobId
parameter in the get_job
method maybe isn't what you think it is ? It is the only answer I can think of at the moment.
This seems to be a decoding problem of the data stored as bytes()
in Redis.
Replacing the default JSONDecoder
with the following did the trick for me:
from rejson import Client, Path
from json import JSONDecoder
class RedisJsonDecoder(JSONDecoder):
def decode(self, s, *args, **kwargs):
if isinstance(s, bytes):
s = s.decode('UTF-8')
return super(RedisJsonDecoder, self).decode(s, *args, **kwargs)
r = Client(decoder=RedisJsonDecoder())
# ...
HTH!
I'm entirely certain this may be a usage issue, but reaching out here as I'm not sure where else to look.
Problem
I have a class
Jobs
which inherits the rejson module classesClient
andPath
. Methods in theJobs
class are called by routes in a flask API.My
/run
route calls themake_job
function, which in turn generates a unique id for that job, and inserts a JSON body into redis. I am using the redis-json docker image from dockerhub.My
/status
route calls theget_job
function, and is supposed to return a JSON object from redis.The problem I'm having is, I can insert JSON objects without issue, but
jsonget
can't seem to find the key I inserted previously.All keys are inserted at the root path.
Workflow
Insert Key via
/run
route:Verify via redis-cli:
Run
/status
route that callsget_job()
, which gets a key usingjsonget
;where
None
is the output ofprint(job)
Code:
Expected results
jsonget
returns and decodes the JSON object stored under the keyname set when inserted.I'm not sure if this is a pathing issue. I've looked at the source, and I see that
jsonget
defaults to the root path.Before using rejson-py, I was using just the raw redis client and encoding/decoding json as needed, but I had issues where the first key I inserted into redis would be rendered
null
, so I switched to rejson-py.Idk if I'm being incredibly stupid here or what..