Reputation: 31736
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
Reputation: 2902
have you seen this gem? https://github.com/nateware/redis-objects, this will help with active record.
Upvotes: 1