hsetex lua command for redis clients
Sets the value of a hash key and updates the expire date at the same time.
HSETEX key 1 firstname walter lastname white
In the example above, key key
expires in 1 second.
$ npm install --save redis-hsetex
The easiest usecase is to use with https://github.com/luin/ioredis as follows:
const Redis = require('ioredis');
const hsetex = require('redis-hsetex');
const redis = new Redis();
redis.defineCommand(hsetex.name, {
lua: hsetex.lua,
numberOfKeys: hsetex.numberOfKeys,
})
Then, just run like any other command:
redis.hsetex('heisenberg', 1, 'firstname', 'walter');
redis.hsetex('heisenberg', 1, 'lastname', 'white');
redis.hsetex('saul_goodman', 1, 'firstname', 'jimmy', 'lastname', 'mcgill');
setTimeout(() => redis.hgetall('heisenberg'), 1100); // At this point, null is returned
There are unit tests and integration tests.
docker-compose up
npm test:unit
npm test:integration
npm test # run both tests
See the LICENSE file for license rights and limitations (MIT).