User Tools

Site Tools


Sidebar

expirationd:alternatives-to

Q. I need expiration for my PoC, and it seems like expirationd is the only way to do it. Are there any other ways? (2016)

A. Let’s say you have some data that looks like this: {user_id, user_name, session}. To add TTL to it, you only need to add one index as follows: {user_id, user_name, session, expire_timestamp} and SPACE_NAME:create_index('expire', {pars={4, NUM}, type='TREE'}).

Code example:

fiber = require('fiber')

function add(user_id, user_name, session)
  SPACE_NAME:insert{user_id, user_name, session, fiber.time64()}
end

-- create a background job
fiber.create(function()
 while true do
  local result = SPACE_NAME.index.expire:select{fiber.time64(), iterator=box.index.LE}
  -- delete the result from SPACE_NAME
  fiber.sleep(0.1) -- poll interval
  end
end)

Comments

Enter your comment. Wiki syntax is allowed:
X V G Y I
 
expirationd/alternatives-to.txt · Last modified: 2018/06/04 19:09 by eabates

Real Time Web Analytics