mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
Added TTL for hash fields
This commit is contained in:
@@ -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': {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user