Skip to content

Client.jsonget not finding key from rootpath #24

@gr33ngiant112

Description

@gr33ngiant112

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 classes Client and Path. Methods in the Jobs class are called by routes in a flask API.

My /run route calls the make_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 the get_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:

{
  "JobID": "5de40954-bf5f-499e-8d6e-f283d4d326c8",
}

Verify via redis-cli:

127.0.0.1:6379> KEYS 5de40954-bf5f-499e-8d6e-f283d4d326c8
1) "5de40954-bf5f-499e-8d6e-f283d4d326c8"
127.0.0.1:6379> 
127.0.0.1:6379> json.get 5de40954-bf5f-499e-8d6e-f283d4d326c8
"{\"gitOrg\":\"test-org\",\"gitRepo\":\"test-repo\",\"job\":{\"inventory\":\"site.ini\",\"playbook\":\"deploy.yml\",\"vars\":\"env=testenv cleanup_keys=true\"}}"

Run /status route that calls get_job(), which gets a key using jsonget;

None
127.0.0.1 - - [12/Jul/2019 16:24:02] "GET /status/5de40954-bf5f-499e-8d6e-f283d4d326c8 HTTP/1.1" 404 -

where None is the output of print(job)

Code:

from rejson import Client, Path

class Jobs(Client, Path):
    Client(host='localhost', port=6379, decode_responses=True)

    def make_job_id(self):
        return uuid.uuid4()

    def make_job(self, data): 
        jobId = str(self.make_job_id())
        self.jsonset(jobId, Path.rootPath(), data)
        return jobId

    def get_job(self, jobId):
        job = self.jsonget(jobId)
        if job:
            print(job)
            return job
        else:
            return False

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..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions