0

I am working with flask and redis. I use the rom redis orm to manage some mildly complex data structures. I want to use a queue of model objects, with the ability to push or pop objects off either end.

I have the following rom model:

class A(rom.Model):
    url = rom.String(required=True, unique=True)()
    t = rom.String()
    delete_at = rom.Float(index=True)
    created_at = rom.Float(default=time.time, index=True)

I see that at the command line when I run obj._columns (with obj being a single instance of class A), that there is an id field. My first thought on how to approach this is to order by id:

queue = A.get_by(id). 

This would allow easy addition to the back of the queue, by setting:

obj.id = len(queue)+1

But I'm not sure how to insert into the 0 element of the list which would require renumbering of the ids of the entire list.

Am I on the right track here? What is the best way to implement a queue?

1 Answer 1

1

I wouldn't implement a queue with rom. If I needed a queue, and I needed to put rom entities in that queue, I would use the raw Redis connection to put entity ids in a Redis list - which offers push and pop from both ends, range scanning, etc.

You can get the raw Redis connection in your example via: A._connection.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.