Skip to content

Commit

Permalink
hash the store id
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumewuip committed Aug 30, 2023
1 parent 8d8717a commit 5d838da
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions rss-to-tana/store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { createClient } = require('redis');
const Log = require('./log');
const crypto = require('crypto')

const REDIS_URL = `redis://${process.env.REDIS_HOST}`

Expand All @@ -11,12 +12,18 @@ client.on('error', error => Log.error('Redis Client Error', error.message));
client.on('reconnecting', () => Log.debug('Redis Client reconnecting...'));
client.on('ready', () => Log.info('Redis Client Ready!'));

// change the prefix to trash all existing ids
// we can also connect to redis and flush the db
//
// flyctl redis connect
// > FLUSHALL
const storeId = (id) => `1-${id}`
const storeId = (id) => {
// we hash the id to have something cleaner than raw url,
// and to be sure to use valid caracters
const hashedId = crypto.createHash('md5').update(id).digest("hex")

// change the prefix to trash all existing ids
// we can also connect to redis and flush the db
//
// flyctl redis connect
// > FLUSHALL
return `1-${hashedId}`
}

const initialize = async () => {
Log.info('Connecting to Redis', REDIS_URL)
Expand Down

0 comments on commit 5d838da

Please sign in to comment.