Skip to content

Commit

Permalink
feat(Redis): handle v4 arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Elvis Hsu committed Jan 31, 2023
1 parent ed61ffe commit 54f3d14
Showing 1 changed file with 13 additions and 67 deletions.
80 changes: 13 additions & 67 deletions lib/plugins/redis/lib/Redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ class Redis {

init(config) {
this.redis = require('redis')

Promise.promisifyAll(this.redis.RedisClient.prototype)
Promise.promisifyAll(this.redis.Multi.prototype)

this.host = config.host
this.port = config.port
this.database = config.database
Expand All @@ -21,92 +17,42 @@ class Redis {
return this
}

connect() {

return new Promise((resolve, reject) => {

this.client = this.redis.createClient({ host: this.host, port: this.port })

this.client.select(this.database)

this.client.on('error', (err) => {

return reject(err)

})

this.client.on('connect', () => {

return resolve(this)

})

async connect() {
this.client = this.redis.createClient({
socket: {
host: this.host,
port: this.port
}
})
await this.client.connect()
this.client.select(this.database)
this.client.on('error', (err) => Promise.reject(err))

return this
}

get(id) {

return new Promise((resolve, reject) => {

this.client.get(id, function(err, reply) {

if (err) return reject(err)

return resolve(reply)

})

})

return this.client.get(id)
}

set(id, data, option, duration) {

return new Promise((resolve, reject) => {

this.client.set(id, data, option, duration, function(err, reply) {

if (err) return reject(err)

return resolve(reply)

})

})

return this.client.set(id, data, option, duration)
}

del(id) {

return new Promise((resolve, reject) => {

this.client.del(id, function(err, reply) {

if (err) return reject(err)

return resolve(reply)

})

})

return this.client.del(id)
}

disconnect() {

if (!this.client) return this

this.client.quit()

return this

}

flushdb() {

return this.client.flushdb()

}

}
Expand Down

0 comments on commit 54f3d14

Please sign in to comment.