Skip to main content

Node & Redis cache Connection

Refer below link to connect both and follow below details for docker integration:


 node.js - Nodejs Redis createClient() function - Stack Overflow


Install the Redis package: First, you need to install the Redis package for Node.js. You can do this using npm by running the command npm install redis.


Initialize Redis client: In your server-side code, you would create a Redis client instance using the redis.createClient() method, which establishes a connection to the Redis server. You can also pass in configuration options such as the Redis server host and port.


Add caching logic: Once you have a Redis client instance, you can add caching logic to your server-side code. This typically involves wrapping a function that retrieves data from a database or external API in a Redis cache check. For example, you might use the Redis get() method to check if the requested data already exists in the cache. If it does, you can return the cached data. If it doesn't, you would fetch the data from the database or API and then store it in Redis cache using the set() method for future requests.


Implement cache expiration: To prevent stale data from being returned from the cache, you can implement a cache expiration time. This can be done using the expire() method in Redis, which sets a time-to-live (TTL) for the cached data.


Integrate with React: Finally, you can integrate the Redis cache with your React app by making API requests to your Node.js server. When your server-side code returns data, it will either be retrieved from the Redis cache or fetched from the database or API, depending on whether the data is already cached. Your React app can then use this data to render UI components as needed.


Overall, adding Redis cache to a Node.js and React server app can help improve performance and reduce the load on your database or external APIs. However, it does require some additional setup and maintenance to ensure that your cache is functioning properly and not causing any issues with data consistency.

for SSO:

Redis cache can help in SSO (Single Sign-On) by reducing the time and resources required to authenticate users across multiple services or applications. SSO typically involves a user logging in once and then being granted access to multiple services without needing to re-enter their credentials each time. However, this can still involve a significant amount of overhead if each service needs to perform its own authentication check each time a user access it.


By using Redis cache to store authentication tokens or session data, services can quickly and easily check whether a user is authenticated without needing to perform a full authentication process each time. For example, when a user logs in, their authentication token can be stored in Redis cache along with a TTL (time-to-live) value that specifies how long the token should remain valid. When the user accesses a different service, that service can check if the token is present in Redis cache and still valid before granting access, rather than requiring the user to log in again.


This can help improve performance and reduce the load on your authentication system, as well as provide a better user experience by allowing users to seamlessly access multiple services without needing to constantly re-enter their credentials. However, it's important to ensure that your Redis cache is properly secured and maintained to prevent any security vulnerabilities or data inconsistencies.


Comments

Popular posts from this blog

HOW-TO:- Solve Moodle 2.7 on MySql 5.7.x Installation

The reason of doing this is I configured my apache for local virtual hosting rather than localhost (available in the next post). I found the error as mentioned below, and I tried different solution to solve it. I did few of the things to solve, they are as follows: Removed and installed MySQL server. Installed mysql 5.7v Installed Moodle 2.7+ stable version  configured and deleted Moodle config.php few times. created and deleted database naming moodle(default created when initialized) and few other names. Gave permission to php5.6 instead of php7.0.2 in Ubuntu 16.04 Here's the Solution, find below lines(183 - 191) or search for " SELECT @@storage_engine " and then replace it from "SELECT @@default_storage_engine" . =======Code Snippets(183 - 191):  =======         // get the default database engine         $sql = " SELECT @@default_storage_engine";         $...

Software Versions You Must Have..!

Google Chrome       Version 29 and Version 37 of Google Chrome works much better than any other version.I updated my Google Chrome but it was lagging,not responding, crashed,contents were loaded very slow and few more.So,finally I found Google Chrome 37 working better,bugs fixed and you can download this to fix the previous problems. 2. KM Player Really awesome player to watch HD Videos,movies.Compatible with all extensions of videos you want to watch whether it is mkv,3gp,flv,HD,4K etc.KM Player has very good 3D mode.You can watch multiple videos at a time.I found version 3.6 & 3.9 useful,but in between versions were very Ads providing, lagging every time when you open the Player. 3. iTunes & Quick Time Player  Hats off to the creator 'Apple Inc.'. iTunes- name is enough.I use default audio player as iTunes.You can feel the sound clarity when you are changing it to other mode like Pop,Rock,Acoustic,Bass etc. iT...

#EspoCRM #Business #Open_Source

Since last few weeks I'm working on EspoCRM - open source business software. I'll edit the post with explanation. just a quick backup. Ref. here:  ORM, How to manage entities and perform queries - EspoCRM Documentation Here are some steps to get started: Here's how you can incorporate your custom search.js script for the Lead entity in a "upgrade safe" way while your pull request is approved: Define your own search.js class in the custom namespace. for example: client/custom/src/views/record/search.js Code: define('custom:views/record/search', 'views/record/search', function (Dep) { return Dep.extend({ WRITE HERE ALL YOUR CUSTOM SEARCH CODE }); }); Define a custom header list view class that will invoke the custom search instead of the core class, for example: client/custom/src/views/header/list.js Code: define('custom:views/header/list', 'views/list', function (Dep) { return Dep.extend({ searchView: 'cu...