Skip to content
Browse files

[FEAT] introducing..... redis!

  • Loading branch information...
1 parent d05ac07 commit 82ab2dd394fd9fcaabdd696d44896c149810a11f Elad Meidar committed Jul 3, 2014
Showing with 44 additions and 3 deletions.
  1. +4 −0 Gemfile
  2. +4 −0 Gemfile.lock
  3. +31 −0 app/models/concerns/thumb_up.rb
  4. +3 −3 config/initializers/fog.rb
  5. +2 −0 config/initializers/redis.rb
View
4 Gemfile
@@ -13,6 +13,10 @@ group :development do
gem 'sqlite3'
end
+# Reids
+gem "hiredis", "~> 0.4.0"
+gem "redis", ">= 2.2.0", require: ["redis", "redis/connection/hiredis"]
+
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'
View
4 Gemfile.lock
@@ -77,6 +77,7 @@ GEM
multi_json (~> 1.0)
formatador (0.2.5)
hike (1.2.3)
+ hiredis (0.4.5)
i18n (0.6.9)
inflecto (0.0.2)
ipaddress (0.8.0)
@@ -131,6 +132,7 @@ GEM
rdoc (4.1.1)
json (~> 1.4)
redcarpet (3.1.2)
+ redis (3.1.0)
sass (3.2.19)
sass-rails (4.0.3)
railties (>= 4.0.0, < 5.0)
@@ -178,6 +180,7 @@ DEPENDENCIES
faker
figaro
fog
+ hiredis (~> 0.4.0)
jbuilder (~> 1.2)
jquery-rails
mini_magick
@@ -186,6 +189,7 @@ DEPENDENCIES
rails (= 4.0.5)
rails_12factor
redcarpet
+ redis (>= 2.2.0)
sass-rails (~> 4.0.2)
sdoc
sqlite3
View
31 app/models/concerns/thumb_up.rb
@@ -0,0 +1,31 @@
+class ThumbUp
+
+ # Add a thumb up for a specific post by a user
+ def ThumbUp.add_thumb_up_for_post(user, post)
+ $redis.multi do
+ $redis.incr "posts:#{post.id}:thumbs_up:count"
+ $redis.sadd "users:#{user.id}:thumbed_up_posts", post.id
+ end
+ true
+ end
+
+ # Remove a thumb up for a specific post by a user
+ def ThumbUp.remove_thumb_up_for_post(user, post)
+ $redis.multi do
+ $redis.decr "posts:#{post.id}:thumbs_up:count"
+ $redis.srem "users:#{user.id}:thumbed_up_posts", post.id
+ end
+ true
+ end
+
+ # Return total number of thumbs up for a post
+ def ThumbUp.count_thumb_ups_for_post(post)
+ $redis.get("posts:#{post.id}:thumbs_up:count").to_i
+ end
+
+ # Return a list of post ids the user thumbed up
+ def ThumbUp.user_thumbed_up_post_ids(user)
+ $redis.smembers "users:#{user.id}:thumbed_up_posts"
+ end
+
+end
View
6 config/initializers/fog.rb
@@ -1,9 +1,9 @@
CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS',
- aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
- aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
+ aws_access_key_id: "eee", #ENV['AWS_ACCESS_KEY_ID'],
+ aws_secret_access_key: "eee" #ENV['AWS_SECRET_ACCESS_KEY']
}
- config.fog_directory = ENV['AWS_BUCKET']
+ config.fog_directory = 'bucket' #ENV['AWS_BUCKET']
config.fog_public = true
end
View
2 config/initializers/redis.rb
@@ -0,0 +1,2 @@
+
+$redis = Redis.new

0 comments on commit 82ab2dd

Please sign in to comment.
Something went wrong with that request. Please try again.