In this case study we will compare Postgres with Redis scoring functions.
Learn how Redis can help improve performance of your relational database driven application.
This example uses Rails, Postgres, and Redis. Please follow the installation guide below. Setup takes 10 to 30 minutes depending on experience with the technologies.
-
Rails on El Capitan. We will be using Postgres, so you don't need to install MySQL in this guide.
-
Follow the Homebrew Postgres instructions in the above guide to install with or download the Postgres app for MAC here. I find the Postgres app to be very useful.
-
Install Redis with Homebrew with
$ brew install redis
. Then follow the prompt to start the server. Run the following to confirm things are working:$ redis-cli redis 127.0.0.1:6379> ping PONG redis 127.0.0.1:6379> set mykey somevalue OK redis 127.0.0.1:6379> get mykey "somevalue"
-
Clone this application.
-
cd
into the application root runbundle install
-
Download the example DB here. To note you can run
$ rake db:seed
to populate the database but it takes 20 minutes to get everything created. Downloading the tarball and usingpg_restore
takes abount 1 minute. -
Create the 'clickbait_development' database with psql or rake.
To create the database with psql:
$ psql psql (9.4.0) Type "help" for help. BrettU=# create database clickbait_development; CREATE DATABASE
OR with rake and Rails
$ rake db:create
-
Restore the database with
$ pg_restore -d clickbait_development clickbait_dev.tar
-
Run
$ rails server
and navigate to localhost:3000. The web app should be running. -
In console query to confirm 365000 score cards have been created.
$ rails c irb(main):001:0> ScoreCard.count (49.9ms) SELECT COUNT(*) FROM "score_cards" => 365000
-
Test redis in rails console:
$ rails c irb(main):001:0> $redis.ping => "PONG" irb(main):002:0>
Congratulations on setting up the demo application. We can have a live demo when in class.
Issues? Google the exception message or open a issue in this repo.
An example application for the Express framework.