![]() ![]() There is so much that you can learn about on their official documentation. There are 9103 other projects in the npm registry using redis. Start using redis in your project by running npm i redis. The new interface is clean and cool, but if you have an existing codebase, you'll want to read the migration guide. To install node-redis, simply: npm install redis. In this article, we have shown how you can use Redis with nodejs with a basic implementation. Latest version: 4.6.5, last published: 2 months ago. Start a redis via docker: docker run -p 6379:6379 -it redis/redis-stack-server:latest. We can see that the time taken for the response is reduced from 1563ms to 33ms which is a huge change. Let us run this code and see the response on the postman to see the results. In our case, searchtext is the key and the data from JSON placeholder API is its value. In case of cache not being there, the server will hit the external API and cache it for subsequent requests.Ĭtex() is the function that takes a key, its value, and duration for the validity of cache as an input. Inside the endpoint, we make Redis cache the data against a specific key and return the response if the appropriate cached data is available without hitting our external API. You can then go to the directory using the following command: 1. Firstly, we have initialized the Redis client on the port of choice. ![]() Let us explain what is happening in the above piece of code. Const searchtext = Ĭlient.get(searchtext, async (err, data) => `) ![]()
0 Comments
Leave a Reply. |