Skip to content

Instantly share code, notes, and snippets.

@harsh4870
Created September 8, 2022 05:21
Show Gist options
  • Save harsh4870/5cf75ba2bfc546297740c4b13be55589 to your computer and use it in GitHub Desktop.
Save harsh4870/5cf75ba2bfc546297740c4b13be55589 to your computer and use it in GitHub Desktop.
Create index in Redis database using Node js
import {createClient, SchemaFieldTypes, AggregateGroupByReducers, AggregateSteps} from 'redis';
const client = createClient();
client.on("error", function(err) {
console.log("Error " + err);
});
client.connect()
try {
await client.ft.create('idx:ipIdx', {
'$.geoname_id': {
type: SchemaFieldTypes.TEXT,
AS: 'geoname_id'
}
}, {
ON: 'JSON'
});
} catch (e) {
if (e.message === 'Index already exists') {
console.log('Index exists already, skipped creation.');
} else {
console.error(e);
process.exit(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment