Created
September 8, 2022 05:21
-
-
Save harsh4870/5cf75ba2bfc546297740c4b13be55589 to your computer and use it in GitHub Desktop.
Create index in Redis database using Node js
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
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