Skip to content

Commit

Permalink
Update redis to v4 and redis-lock to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksTeresh committed Nov 20, 2024
1 parent 3ce234b commit 1cf39ba
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 244 deletions.
143 changes: 96 additions & 47 deletions importer-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion importer-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"node-cron": "^3.0.1",
"node-nats-streaming": "^0.2.6",
"pg": "^8.12.0",
"redis": "^3.1.1",
"redis": "^4.0.0",
"winston": "^3.2.1",
"winston-gelf-transporter": "^1.0.2"
},
Expand Down
31 changes: 16 additions & 15 deletions importer-api/src/utils/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,37 @@ const redisRetry = ({ attempt, error }) => {

const client = redis.createClient({
url: process.env.REDIS_URI,
retry_strategy: redisRetry
reconnectStrategy: redisRetry
})

client.on('connect', () => logger.info('REDIS CONNECTED'))
client.on('ready', () => logger.info('REDIS READY'))
client.on('error', () => logger.error('REDIS ERROR'))

const redisPromisify = async (func, ...params) =>
new Promise((res, rej) => {
func.call(client, ...params, (err, data) => {
if (err) rej(err)
else res(data)
})
client
.connect()
.then(() => {
logger.info('Connected to Redis')
})
.catch(error => {
logger.error('Failed to connect to Redis', error)
})

const sadd = async (key, val) => await redisPromisify(client.sadd, key, val)
const sadd = async (key, val) => await client.sAdd(key, val)

const smembers = async key => await redisPromisify(client.smembers, key)
const smembers = async key => await client.sMembers(key)

const get = async key => await redisPromisify(client.get, key)
const get = async key => await client.get(key)

const set = async (key, val) => await redisPromisify(client.set, key, val)
const set = async (key, val) => await client.set(key, val)

const expire = async (key, val) => await redisPromisify(client.expire, key, val)
const expire = async (key, val) => await client.expire(key, val)

const del = async key => await redisPromisify(client.del, key)
const del = async key => await client.del(key)

const incrby = async (key, val) => await redisPromisify(client.incrby, key, val)
const incrby = async (key, val) => await client.incrBy(key, val)

const publish = async (channel, message) => await redisPromisify(client.publish, channel, message)
const publish = async (channel, message) => await client.publish(channel, message)

module.exports = {
sadd,
Expand Down
52 changes: 0 additions & 52 deletions importer-db-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion importer-db-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"morgan": "^1.10.0",
"pg": "^8.12.0",
"pg-hstore": "^2.3.4",
"redis": "3.1.2",
"sequelize": "^6.0.0",
"winston": "^3.3.3"
},
Expand Down
53 changes: 0 additions & 53 deletions importer-db-api/src/utils/redisClient.js

This file was deleted.

Loading

0 comments on commit 1cf39ba

Please sign in to comment.