Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance ephemeral data blobs API #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions lib/redisio.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,14 @@ async function retrieveFrameData(fmtOrKey, stream_index = 0, pts = 0, idx = '')
return frameData;
}

async function storeBlob (data) {
async function storeBlob (data, customKey = '') {
let redis = await redisPool.use();
let key = `${config.redis.prepend}:blob:${Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER)}`;
let key = `${config.redis.prepend}:blob:`;
if (customKey && typeof customKey === 'string') {
key += customKey;
} else {
key += `${Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER)}`;
}
let result = await redis.setBuffer(key, data, 'PX', config.redis.ephemeralTTL);
redisPool.recycle(redis);
if (result != 'OK') {
Expand All @@ -741,6 +746,19 @@ async function retrieveBlob (key) {
return result;
}

async function checkBlob (key) {
let redis = await redisPool.use();
if (typeof key === 'number') {
key = `${config.redis.prepend}:blob:${key}`;
}
if (!key.startsWith(`${config.redis.prepend}:blob:`)) {
key = `${config.redis.prepend}:blob:${key}`;
}
let result = await redis.pexpire(key, config.redis.ephemeralTTL);
redisPool.recycle(redis);
return (result === 1) ? key : null;
}

async function createEquivalent (source, target) {
if (source.url && typeof source.url === 'string') {
source = source.url;
Expand Down Expand Up @@ -1266,6 +1284,7 @@ module.exports = {
retrieveFrameData,
storeBlob,
retrieveBlob,
checkBlob,
resetCaches,
createEquivalent,
createRendition,
Expand Down