Banks Nosql, means "Not only SQL":
These arose from the need to scale relational databases with ACID properties in high-availability web projects that operate on a large scale. Its main features are high performance, scalability, easy replication and structured data support.
This break with SQL standards always causes great repercussion and many discussions loaded with feelings and emotions, but the truth is that relational databases still serve to solve many problems that not always (You see, not always) can be solved with Nosql banks, for example:
- Need for strong data consistency, well-defined typing, etc;
- Complex searches that require a relational data model for instructions and join operations, for example;
- Data that exceeds the availability of server memory, however we may use swap, no one wants to impair performance in this case.
Nosql Redis:
Storage of user sessions
This is a very simple template on how to use Redis to save a user’s session information.
For each session, a key is generated that is saved to the browser cookie. With this key, the system has access to a hash with information from this session: login status, clicked products and advertisements, language preferences and other temporal settings, which expire after a few hours.
The benefit of not storing such session information directly in the cookie is evident: we have gained the data integrity security, not at the risk of some malicious user modifying them. With Redis, we use simple get/set operations to access this data directly from the server’s memory (or servers, if there is more than one), no waste of resources, thanks to efficient expiration system promoted by this Nosql.
The expiration algorithm does not monitor 100% of the keys that can expire. Just like most cache systems, keys are expired when a client attempts to access them. If the key is expired the value is not returned and the record is removed from the database.
In databases that record many data that lose validity over time, as in this example, some keys would never be accessed again consequently they would never be removed. These keys need to be removed somehow, so every second Redis tests a random set of keys that may be expired. The algorithm is simple, with each run:
- Tests 100 keys with set expiration.
- Delete all expired keys.
- If more than 25 keys are invalid the algorithm resumes from 1.
This probabilistic logic continues to expire until our set of valid Keys is close to 75% of the records.
Research source: Link Nosql Redis
Thanks for the tip, I do not understand why someone gave -1, I understand little of Redis yet but the tip is valid yes, the product information does not change constantly.
– Filipe Moraes
Do you know of any scenarios where Redis is used to maintain authentication states? That is, the user logs in and something is persisted and read in Redis in the next operations? I have a scenario that I want to authenticate with JWT and use Redis but I don’t know if it applies to the case.
– Francisco Souza