Last active
April 19, 2017 07:15
-
-
Save joshuacullenlux/39bf1796cbc700775d00eccdd0fd0e0f to your computer and use it in GitHub Desktop.
Redis availability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*Set a range* | |
hotel:{ID}:room{ID}:{YEAR}:{DAY} range {RANGE} avail {AVAILABILITY} | |
172.26.0.2:6379> hmset hotel:100:room:2:2017:1 range 31 availability 5 | |
OK | |
*Get a range* | |
172.26.0.2:6379> HGETALL hotel:100:room:2:2017:1 | |
1) "range" | |
2) "31" | |
3) "availability" | |
4) "5" | |
*Get availability for a primary day* | |
//Check if exists | |
172.26.0.2:6379> EXISTS HMGET hotel:100:room:2:2017:1 | |
(integer) 1 | |
//Get | |
172.26.0.2:6379> HMGET hotel:100:room:2:2017:1 availability | |
1) "5" | |
return 5 | |
*Get availability for a day (5) that falls in a range* | |
172.26.0.2:6379> EXISTS HMGET hotel:100:room:2:2017:5 | |
(integer) 0 | |
//Get all ranges for that room | |
172.26.0.2:6379> keys hotel:100:room:2:2017:* | |
1) "hotel:100:room:2:2017:1" | |
2) "hotel:100:room:2:2017:32" | |
//Check closest key for range and return availability because it falls within | |
172.26.0.2:6379> HGETALL hotel:100:room:2:2017:1 | |
1) "range" | |
2) "31" | |
3) "availability" | |
4) "5" | |
return 5 | |
*Decrement availability for a day (10)* | |
//Same find range logic as above then split the range and decrement | |
172.26.0.2:6379> EXISTS HMGET hotel:100:room:2:2017:10 | |
(integer) 0 | |
//Get all ranges for that room | |
172.26.0.2:6379> keys hotel:100:room:2:2017:* | |
1) "hotel:100:room:2:2017:1" | |
2) "hotel:100:room:2:2017:32" | |
//Check closest key for range and return availability because it falls within | |
172.26.0.2:6379> HGETALL hotel:100:room:2:2017:1 | |
1) "range" | |
2) "31" | |
3) "availability" | |
4) "5" | |
//Create new ranges | |
172.26.0.2:6379> hmset hotel:100:room:2:2017:1 range 9 availability 5 | |
OK | |
172.26.0.2:6379> hmset hotel:100:room:2:2017:10 range 1 availability 4 | |
OK | |
172.26.0.2:6379> hmset hotel:100:room:2:2017:11 range 21 availability 5 | |
OK | |
//New ranges are available | |
172.26.0.2:6379> keys hotel:100:room:2:2017:* | |
1) "hotel:100:room:2:2017:10" | |
2) "hotel:100:room:2:2017:1" | |
3) "hotel:100:room:2:2017:11" | |
4) "hotel:100:room:2:2017:32 | |
172.26.0.2:6379> hgetall hotel:100:room:2:2017:10 | |
1) "range" | |
2) "1" | |
3) "availability" | |
4) "4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment