CPSC/DATA 350 - Applications of Databases - Fall 2024
Possible experience: +40XP
Due: Sunday, Nov. 3, midnight
In the second installment of your DB World Tour project, you'll add the next fourth of your website, backed by a Redis database.
Identify some different aspect of your assignment #6 topic that would lend itself well to the data structure types Redis provides. Remember that these are atomic key/value pairs, sets, hashes, linked lists, and sorted sets.
As before, pick something interesting and non-trivial, but not exhaustive.
To get Python bindings for the Redis commands, make sure to run:
$ pip install redis
after activating your virtual environment. (You only need to do this once.)
Also take a moment to ensure you can bring up the Redis command-line interface:
$ redis-cli
and that you get a happy prompt. (Type exit to exit.)
For this assignment, each student will be assigned a different logical Redis database instance, which will correspond to different key-value stores (so you're not all reading and writing on top of each other). The number of your instance has been added to the port numbers page.
When you connect to Redis in Python, you'll do this:
import redis r = redis.Redis(db=N, decode_responses=True)
where N is the number of your Redis instance.
When you talk to Redis via its command line interface, you'll type:
$ redis-cli 127.0.0.1:6379> select N 127.0.0.1:6379[N]> ... more Redis commands ...
to do so, again replacing N with the number of your Redis instance.
PLEASE do not be a jerk and go into someone else's Redis instance and mess around in it, even as a joke. Not only will this be considered an Honor Code violation, but if the person whose database you hacked is sufficiently pissed, it might even cost you your life.
Your assignment #7 should fulfill the following requirements:
Think carefully about which data structures would be appropriate for the kind of data you want to track. If you choose poorly, your database and your code is going to be a mess.
My crime database uses two Redis data structures to hold information about the shows my wife and I watch together. A linked list called tour:queue holds the titles of our "queue" of shows that we plan to watch soon. A sorted set called tour:time_investments keeps track of the total amount of our lives (in minutes) we've spent watching each show. Here's what they look like from the Redis command-line interface:
127.0.0.1:6379[43]> lrange tour:queue 0 -1 1) "Innocent" 2) "Mare of Easttown" 3) "No.1 Ladies Detective Agency" 127.0.0.1:6379[43]> zrevrange tour:time_investments 0 -1 withscores 1) "A Touch of Frost" 2) "110" 3) "Bang" 4) "95" 5) "Injustice" 6) "90" 7) "No.1 Ladies Detective Agency" 8) "45" 9) "Goliath" 10) "45" 11) "Columbo" 12) "45"
My revised page now looks like:
The new elements on the right-side are from Redis. The queue is shown at the top in our planned watching order. Choosing an entry from the "Show to queue:" drop-down, and pressing the "Add to queue" button, refreshes the page and adds the show to the queue in the bottom position. When we watch a show, we press the "Watch!" button (which includes the show at the top of the queue) and enter the number of minutes for that episode. The show is then dequeued from the top of the queue, and the total time for that show is incremented in the sorted set accordingly.
This is just how I chose to do my Redis stuff. You do not need to imitate these choices whatsoever. Use two different Redis data structures in whatever way you wish. You do not need to have a queue, or a total time investment list, or even use a linked list or sorted set at all. Be creative.
Send me an email with subject line "CPSC/DATA 350 Assignment #7 turn-in". In the body of the email, simply paste the link to the landing page of your website.
Come to office hours, or send me email with subject line "CPSC 350 Assignment #7 help!!"