Project

ohm-expire

0.02
No commit activity in last 3 years
No release in over 3 years
A simple but useful plugin for Ohm that enables control over Redis TTL through Ohm
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.1

Runtime

>= 0.1.5
 Project Readme

ohm-expire

Ohm plugin that exposes ttl control over modules

Getting started

Install gem by running:

$ [sudo] gem install ohm-expire

On your source code add:

require "ohm/expire"

After this you need to tell your Ohm Model that it needs to use this extension. Here is an example of a module:

class Model < Ohm::Model

    include Ohm::Expire

    TTL = 5

    attribute :hash
    index :hash

    expire Model::TTL

    attribute :data
end

This will create this Ohm Model class with an expire of 5 seconds

Updating TTL

It's easy to update the TTL after creating a Model. There is also the possibility to simple update the ttl with the default value (the one that was defined on the Model)

Taking the example above:

m = Model.create(:hash => "123")
m.update_ttl 30 # Updated to 30 seconds
m.update_ttl # Updated to 5 seconds (Model::TTL)

Getting TTL

To get the TTL of a given model:

m = Model.create(:hash => "123")
m.get_ttl