Skip to content

Instantly share code, notes, and snippets.

@joeywhelan
Created November 5, 2023 18:37
Redis JSON and string loads
async #insertProperties() {
const csvStream = fs.createReadStream("./data/co.csv").pipe(parse({ delimiter: ",", from_line: 2}));
let id = 1;
for await (const row of csvStream) {
const doc = {
"id": id,
"address": {
"coords": `${row[0]} ${row[1]}`,
"number": row[2],
"street": row[3],
"unit": row[4],
"city": row[5],
"state": "CO",
"postcode": row[8]
},
"owner": {
"fname": uniqueNamesGenerator({dictionaries: [names], style: 'capital', length: 1, separator: ' '}),
"lname": uniqueNamesGenerator({dictionaries: [names], style: 'capital', length: 1, separator: ' '}),
},
"type": `${TYPES[Math.floor(Math.random() * TYPES.length)]}`,
"availability": this.#getAvailability(),
"rate": Math.round((Math.random() * 250 + 125) * 100) / 100
}
await this.client.json.set(`property:${id}`, '.', doc);
id++;
if (id > MAX_PROPERTIES) {
break;
}
}
async #insertZips() {
const csvStream = fs.createReadStream("./data/zip_lat_long.csv").pipe(parse({ delimiter: ",", from_line: 2}));
for await (const row of csvStream) {
const zip = row[0];
const lat = row[1];
const lon = row[2];
await this.client.set(`zip:${zip}`, `${lon} ${lat}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment