Created
February 6, 2024 13:15
-
-
Save lappi-lynx/a6862b41c75989ef32aafda48aafed54 to your computer and use it in GitHub Desktop.
Simple redis caching module
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
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