Skip to content

Instantly share code, notes, and snippets.

@asdrubalivan
Created July 16, 2019 18:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save asdrubalivan/d87373559e40268fe4c648bab94d0113 to your computer and use it in GitHub Desktop.
Script to search by username using nodebb
const redis = require("redis");
const { promisify } = require("util");
const client = redis.createClient({
db: "5" // Change database as needed
});
const getUserIds = () =>
new Promise((resolve, reject) => {
client.keys("user:*", (err, result) => {
if (err) reject(err);
const toResolve = result
.filter(key => /^user\:\d+$/.test(key))
.map(p => p.replace(/^user\:/, ""));
return resolve(toResolve);
});
});
const getUserData = id =>
new Promise((resolve, reject) => {
client.hgetall(`user:${id}`, function all(err, result) {
if (err) reject(err);
return resolve(result);
});
});
const getAllUsers = async () => {
const ids = await getUserIds();
return Promise.all(ids.map(getUserData));
};
(async function main() {
const myArgs = process.argv.slice(2);
const data = await getAllUsers();
const filteredData = data.filter(d => d.username === myArgs[0]);
console.log(
"Results",
filteredData.map(({ username, password, uid }) => ({
username,
password,
uid
}))
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment