Created
April 30, 2014 08:17
-
-
Save seyhunak/7fd20a624a8c09a0fe09 to your computer and use it in GitHub Desktop.
Get & Set To Redis Cache - Rails 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_from_cache(uid, key) | |
redis_available = true | |
Sidekiq.redis do |connection| | |
begin | |
objects = Rails.cache.read("user:#{uid}:#{key}") if connection | |
rescue Redis::CannotConnectError | |
ExceptionNotifier.notify_exception(e) | |
redis_available = false | |
end | |
end | |
end | |
def set_to_cache(uid, key, queryset) | |
redis_available = true | |
Sidekiq.redis do |connection| | |
begin | |
Rails.cache.write("user:#{uid}:#{key}", queryset, expires_in: 1.aay) if connection | |
rescue Redis::CannotConnectError | |
ExceptionNotifier.notify_exception(e) | |
redis_available = false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment