Reputation: 36205
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?
Upvotes: 0
Views: 295
Reputation: 727
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
.
Upvotes: 1