1

I'm using Redis to store a bunch of "Foos" in a hash:

foo:<id> => {
    name = 'whatever',
    status = 'incomplete|complete|removed',
    user = <user_id>,
    ...
}

I want to set up an index so I can pull Foos with a particular status for a particular user. Best thing I've come up with is using sets named like so:

foo:user:<user_id>:status:<status> => [ <foo_id>, <foo_id2>, ... ]

But that seems very clunky, and I'd have to make sure to track the old status and remove it from one set when I change the status, to keep data consistent. Is there a more clever structure I can use here?

0

1 Answer 1

1

I think the way you're thinking about storing this stuff is fine. You can always change the foo:user:<user_id>:status:<status> name, if you think it's too long, but the idea makes sense. The one thing I'd add is you should make a short lua function that updates statuses for you by getting the old status from a foo, updating that foo's status to the new status, and then updating the old status' set and the new status' set. Those operations are each O(1), so it won't be expensive (especially since its Lua), and since everything will be managed by one little script, you won't need to worry about doing it all in your code every time.

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.