Added TTL for hash fields

This commit is contained in:
Stela Augustinova
2025-12-10 16:46:13 +01:00
parent d5bd40873e
commit a79896aa2e
2 changed files with 16 additions and 2 deletions

View File

@@ -538,9 +538,23 @@ const driver = {
} }
case 'hash': { case 'hash': {
const res = await dbhan.client.hscan(key, cursor, 'COUNT', count); const res = await dbhan.client.hscan(key, cursor, 'COUNT', count);
const fields = _.chunk(res[1], 2);
// Get TTL for each hash field (Redis 7.4+)
const items = await Promise.all(
fields.map(async ([fieldKey, fieldValue]) => {
try {
const ttl = await dbhan.client.call('HTTL', key, 'FIELDS', 1, fieldKey);
return { key: fieldKey, value: fieldValue, TTL: ttl && ttl[0] !== undefined ? ttl[0] : null };
} catch (e) {
return { key: fieldKey, value: fieldValue };
}
})
);
return { return {
cursor: parseInt(res[0]), cursor: parseInt(res[0]),
items: _.chunk(res[1], 2).map((item) => ({ key: item[0], value: item[1] })), items,
}; };
} }
case 'stream': { case 'stream': {

View File

@@ -63,7 +63,7 @@ const driver = {
{ {
name: 'hash', name: 'hash',
label: 'Hash', label: 'Hash',
dbKeyFields: [{ name: 'key' }, { name: 'value' }], dbKeyFields: [{ name: 'key' }, { name: 'value' }, { name: 'TTL' }],
keyColumn: 'key', keyColumn: 'key',
addMethod: 'hset', addMethod: 'hset',
showItemList: true, showItemList: true,