mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 02:06:01 +00:00
redis: support for redis streams
This commit is contained in:
@@ -297,6 +297,14 @@ const driver = {
|
||||
switch (method) {
|
||||
case 'mdel':
|
||||
return await this.deleteBranch(pool, args[0]);
|
||||
case 'xaddjson':
|
||||
let json;
|
||||
try {
|
||||
json = JSON.parse(args[2]);
|
||||
} catch (e) {
|
||||
throw new Error('Value must be valid JSON. ' + e.message);
|
||||
}
|
||||
return await pool.xadd(args[0], args[1] || '*', ..._.flatten(_.toPairs(json)));
|
||||
}
|
||||
return await pool[method](...args);
|
||||
},
|
||||
@@ -332,6 +340,22 @@ const driver = {
|
||||
items: _.chunk(res[1], 2).map((item) => ({ key: item[0], value: item[1] })),
|
||||
};
|
||||
}
|
||||
case 'stream': {
|
||||
const res = await pool.xrange(key, cursor == 0 ? '-' : cursor, '+', 'COUNT', count);
|
||||
let newCursor = 0;
|
||||
if (res.length > 0) {
|
||||
const id = res[res.length - 1][0];
|
||||
const idParts = id.split('-');
|
||||
newCursor = `${idParts[0]}-${parseInt(idParts[1] + 1)}`;
|
||||
}
|
||||
return {
|
||||
cursor: newCursor,
|
||||
items: res.map(([id, vals]) => ({
|
||||
id,
|
||||
value: JSON.stringify(_.fromPairs(_.chunk(vals, 2)), undefined, 2),
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
@@ -64,6 +64,14 @@ const driver = {
|
||||
addMethod: 'hset',
|
||||
showItemList: true,
|
||||
},
|
||||
{
|
||||
name: 'stream',
|
||||
label: 'Stream',
|
||||
dbKeyFields: [{ name: 'id' }, { name: 'value' }],
|
||||
keyColumn: 'id',
|
||||
addMethod: 'xaddjson',
|
||||
showItemList: true,
|
||||
},
|
||||
],
|
||||
|
||||
showConnectionField: (field, values) => {
|
||||
|
||||
Reference in New Issue
Block a user