concept47
concept47

Reputation: 31736

Which design pattern to apply when using Redis as a datastore with Rails

I'm thinking about using Redis for storing things I don't want to pull out of the database, user counts, follower ids, long urls that Rails has to spit out ... etc and I'm trying to figure out a way to design my app to do this.

I was wondering if to take the approach that redis is a persistent datastore that I have to load up before I run the app.

So something like

Post < ActiveRecord::Base
   def thumbnail_url
      #get redis value
   end
end

or should I actually be thinking of Redis as a more transient kind of storage where I would do the same thing like this

Post < ActiveRecord::Base
   def thumbnail_url
      if redis value exists
         get it
      else
         do some ruby stuff and return string #hit Active record
      end
   end
end

Or is there another way I should be thinking about this?

Upvotes: 0

Views: 442

Answers (1)

MorphicPro
MorphicPro

Reputation: 2902

have you seen this gem? https://github.com/nateware/redis-objects, this will help with active record.

Upvotes: 1

Related Questions