Registry / database / redis-hsetex

redis-hsetex

JSON →
library6.0.0jsnpmunverified

Provides a Lua script implementing the HSETEX Redis command, which sets a hash field value and simultaneously updates the key expiration. The package is at version 6.0.0, requiring Node >=20, and is designed to be used with ioredis or any Redis client that can define custom commands via Lua scripts. It differentiates by offering a single-purpose Redis extension for atomic hash set + expire operations, unlike generic Redis clients or multi-command patterns. The release cadence is irregular; updates are triggered by library compatibility or bug fixes. It is a minimal dependency with no runtime dependencies.

npm install redis-hsetex
INSTALL
IMPORT
SIG · REDIS-HSETEX
R
redis-hsetex
databasejavascriptv6.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

hsetex
const hsetex = require('redis-hsetex')
import hsetex from 'redis-hsetex'
Package uses CommonJS; ESM import will fail. Use require().
hsetex.lua
const hsetex = require('redis-hsetex'); redis.defineCommand(hsetex.name, { lua: hsetex.lua, numberOfKeys: hsetex.numberOfKeys })
const { lua, name, numberOfKeys } = require('redis-hsetex')
Only the full hsetex object exposes `name`, `lua`, and `numberOfKeys`; destructuring is fine but ensure all three are used.
hsetex.name
const hsetex = require('redis-hsetex'); redis.defineCommand(hsetex.name, ...)
redis.defineCommand('hsetex', ...)
Always use hsetex.name to get the correct command name; hardcoding may cause mismatch if package changes.

Initializes ioredis with the HSETEX command using redis-hsetex, sets multiple fields, retrieves them, and demonstrates auto-expiry.

const Redis = require('ioredis'); const hsetex = require('redis-hsetex'); const redis = new Redis(); redis.defineCommand(hsetex.name, { lua: hsetex.lua, numberOfKeys: hsetex.numberOfKeys, }); async function demo() { await redis.hsetex('myhash', 10, 'field1', 'value1', 'field2', 'value2'); const data = await redis.hgetall('myhash'); console.log(data); // { field1: 'value1', field2: 'value2' } // After 10 seconds, the key expires } demo().catch(console.error);
Debug
Known issues
gotchaThe package requires Node >=20. Using older Node versions will cause runtime errors.
fix
Upgrade Node to version 20 or later.
affects: <6.0.0
gotchaThis is a CommonJS-only package; ES module imports (import) will not work.
fix
Use require() instead of import.
affects: >=0.0.0
gotchaThe HSETEX command expects 'key' and 'seconds' as first two arguments. Passing arguments in wrong order leads to unexpected behavior.
fix
Ensure the first argument is the key, second is TTL in seconds, then field-value pairs.
affects: >=0.0.0
gotchaThe package is designed for ioredis's defineCommand. Using it with other Redis clients (e.g., node-redis) requires manual Lua script loading.
fix
If using node-redis, load the script via redisClient.scriptLoad(hsetex.lua).
affects: >=0.0.0
Errors
Common errors & fixes
Failed to load the script. Please check the script content.
Passing the script content incorrectly or using wrong number of keys.
fix
Ensure you pass hsetex.lua as the lua property and hsetex.numberOfKeys as numberOfKeys in defineCommand.
ERR wrong number of arguments for 'hsetex' command
Missing required arguments (key, seconds) or incorrect order.
fix
Call redis.hsetex(key, seconds, field, value, ...). Minimum arguments: key, seconds, field, value.
TypeError: redis.defineCommand is not a function
Using a Redis client that does not support defineCommand (e.g., node-redis).
fix
Use ioredis client, or manually load the script with scriptLoad and call EVALSHA.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Meta
1
Resources
redis-hsetex — npm install redis-hsetex · libregistry