Skip to content

Instantly share code, notes, and snippets.

@lappi-lynx
Created February 6, 2024 13:15
Show Gist options
  • Save lappi-lynx/a6862b41c75989ef32aafda48aafed54 to your computer and use it in GitHub Desktop.
Save lappi-lynx/a6862b41c75989ef32aafda48aafed54 to your computer and use it in GitHub Desktop.
Simple redis caching module
require 'redis'
module RedisStore
EXPIRATION_TIME_SECONDS = 1 * 24 * 60 * 60 # 1 day
def redis
@redis ||= Redis.new(host: 'localhost', port: 6379)
end
def set_cache(id, val)
redis.setex(id, EXPIRATION_TIME_SECONDS, val)
end
def get_from_cache(id)
redis.get(id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment