Posts

Showing posts with the label redis

Revoking JWT with Redis in NestJS

Image
Introduction In the previous article, I provided instructions on using NestJS with JWT, and you may also realize that if you use JWT, once a token is issued, it cannot be revoked. This means that if you have a token that hasn't expired yet, you can continue to use the service. For small systems that do not prioritize security, this might not be a major issue and can be simply resolved by deleting the token from the frontend when the user logs out. However, if you need to build a system with extremely high security, where the token must be invalidated upon logout so that no one can use it to access the service, this article will guide you through how to achieve that. To do this, we will use Redis (which I have already guided you on in this article) to store tokens that have not expired but are requested to be deleted. The storage duration for these tokens will be exactly the time remaining until they expire. Thus, after applying Redis, the operation of tokens will be as follows: If ...

Guide to using Redis with NestJS

Image
Introduction Redis is an in-memory data structure store, used as a database, cache, and message broker. Redis provides very fast access speeds due to storing data in RAM, helping optimize performance for applications requiring low latency and high concurrent query handling capability. Valkey is an open-source project created to continue the development of Redis after Redis changed its license towards a commercial one. Valkey is fully compatible with existing Redis protocols and libraries, bringing advantages in stability, being completely free (BSD-licensed), and supported by a large community and leading technology corporations. Detail First, create a docker-compose.yml file with the following content services : valkey : image : valkey/valkey:8.0-alpine container_name : valkey ports : - "6379:6379" command : valkey-server --save 60 1 --loglevel warning The above code uses Docker Compose to initialize a container running Valkey, exposing port 6379 for ...

Redis Fundamentals

Image
Introduction Redis is the world's fastest in-memory database. It offers cloud and on-premises solutions for caching, vector search, and NoSQL databases. In-memory is a concept related to how data is stored and accessed in a computer. When we talk about in-memory, we refer to storing data directly in the computer's RAM (Random Access Memory) rather than on a hard drive. Here are some key points about in-memory storage: Storing data in RAM :   When data is stored in-memory , it is kept in the computer's RAM . RAM has faster access speeds compared to hard drives, allowing for quicker data querying and processing.   The read and write speed of RAM is very fast, typically reaching several GB/s . The read and write speed of SSDs ( Solid State Drives ) usually starts from 320 MB/s and can reach thousands of megabytes per second. The read and write speed of HDDs ( Hard Disk Drives ) is lower, generally ranging from 80 MB/s to 160 MB/s. In-memory data is often used f...