Created
February 7, 2022 20:22
-
-
Save blixxurd/b40a131ff77509187ca495a160216d26 to your computer and use it in GitHub Desktop.
Redis Controller for keeping track of URLs. Converts methods to promises.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const redis = require('redis'); | |
class RedisController { | |
constructor(set, redisConfig = {}) { | |
this.set = set; | |
this.client = redis.createClient(redisConfig); | |
} | |
keyExists(url) { | |
return new Promise((resolve) => { | |
this.client.EXISTS(url, (err, res) => { | |
return resolve(!!res); | |
}); | |
}); | |
} | |
exists(url) { | |
return new Promise((resolve) => { | |
this.client.SISMEMBER(this.set, url, (err, res) => { | |
return resolve(!!res); | |
}); | |
}); | |
} | |
add(url) { | |
return new Promise((resolve) => { | |
this.client.SADD(this.set, url, (err, res) => { | |
return resolve(!!res); | |
}); | |
}); | |
} | |
getUrlsFromQueue() { | |
return new Promise((resolve, reject) => { | |
}); | |
} | |
deleteSet() { | |
return new Promise((resolve) => { | |
this.client.DEL(this.set, (err, res) => { | |
return resolve(!!res); | |
}); | |
}); | |
} | |
deleteUrlsFromQueue(urls) { | |
} | |
} | |
module.exports = RedisController; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment