Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Created April 30, 2014 08:17
Show Gist options
  • Save seyhunak/7fd20a624a8c09a0fe09 to your computer and use it in GitHub Desktop.
Save seyhunak/7fd20a624a8c09a0fe09 to your computer and use it in GitHub Desktop.
Get & Set To Redis Cache - Rails 4
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