This is a simple application accompanying a three-part Summa blog post. It uses:
- Ruby 2.0
- Rails 4.0
- Redis
And it's built to be deployed on Heroku. It's not something you should use in the real world but instead it's built to demonstrate how these different tools are used.
First, check out this repository. I use the command-line, so it would look like this:
$ git clone git@github.com:cwinters/polltron.git
Cloning into 'polltron'...
remote: Counting objects: 69, done.
remote: Compressing objects: 100% (51/51), done.
remote: Total 69 (delta 7), reused 69 (delta 7)
Receiving objects: 100% (69/69), 15.
Now let Bundler do its work:
$ cd polltron
polltron: $ bundle install
Using rake (10.1.1)
...
Using uglifier (2.4.0)
Using unicorn (4.7.0)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
The exercise has a number of references like this (Tag: v0.0.2)
. You can advance (or retreat) to
that particular point in the exercise by checking out that tag in git:
polltron: $ git co v0.0.2
We store a few different types of models in Redis. (Traditionally these might be better done in a relational database but we're using Redis for everything.)
Poll
Key poll.{numeric ID}
Value: STRING; serialized JSON with keys:
- id
- name
- choices: array of numeric IDs
Poll choice
Key: poll_choice.{numeric ID}
Value: STRING; serialized JSON with keys:
- id
- name
- poll (full redis key)
User
Key: user.{numeric ID}
Value: STRING; serialized JSON with keys:
- id
- name
Poll created
Key: poll_created
Value: ZSET; score is timet when poll created; value is poll.{numeric ID}
User created
Key user_created
Value: ZSET; score is timet of creation, value is user.{numeric ID}
User polls
Key: user.{numeric ID}.polls
Value: ZSET; score is timet of poll creation, value is poll.{numeric ID}
User votes
Key: user.{numeric ID}.votes
Value: ZSET; score is timet of vote, value is poll.{numeric ID}.choices {index}
Vote count by poll
Key: poll.{numeric ID}.vote_count
Value: HASH; key is choice ID, value is count of that choice; additional key TOTAL
which is the sum.
Vote by poll
Key: poll.{numeric ID}.votes
Value: ARRAY; value is {timet} poll.{numeric ID}.choices {index}
Vote time
Key: vote_time
Value: ZSET; score is timet of vote, value is poll.{numeric ID}
Vote count
Key: vote_count
Value: ZSET; score is total vote count, value is poll.{numeric ID}