Reputation: 1
I have a bookings which are stored in hash HSET bookings booking_id "1",booking_info .. ..
and have a zset with timestamp as a score and value as a booking_id these are the booking create date e.g zet create_date i also have a 4 types of sets which have a status as per the bookings set with values as booking_ids e.g bookings:pending values booking_ids bookings:confirmed values booking_ids and the last one is the same as zet with bookings which contains zset deadline_date of the booking.
So now i need to show the bookings which are confirmed and having a create date range from date 1 to date 2 and with deadline date from date 1 to date 2 Thanks
Upvotes: 0
Views: 119
Reputation: 5236
To me, there a few possible options for approaching the problem depending on how much of the processing you want to defer to Redis (or not). Your basic steps are:
Identify the booking IDs that have a creation date in the desired range. The tag on the question indicates you're using phpredis
, so you can probably get this with zRangeByScore
.
Do the same to identify the IDs that have a deadline date in the desired range.
Identify the booking IDs that are confirmed. Based on your question description, this is already stored in Redis as a set.
The task now is to identify the booking IDs that exist in all three sets. You can:
zRangeByScore
should already retrieve arrays representing the booking IDs falling in the proper ranges for creation date as well as deadline, and sMembers
can get you an array containing all the booking IDs from the confirmed set.zRangeByScore
back into Redis as a set using sAdd
. You could then get Redis to give you the intersection between this set and the confirmed bookings set with sInter
, which should return an array of booking IDs satisfying all of these criteria. If you go this route, you will probably want to remember to delete whichever set you created to hold all of the IDs satisfying the creation date and deadline conditions.Either way, once you get all of the IDs you can retrieve the booking information associated with each ID using hGet
.
Upvotes: 1