No video

Store the HTTP Session into Redis | Spring Boot Backend #3.4

In this video I show how to store the HTTP session into Redis with Spring Boot. I show the necessary dependencies and how to configure Spring Boot to not have the HTTP session stored only in the application.
This is the fourth part of the third video of a playlist where I show how to create a Spring Boot Backend how to create a website: • Spring Boot
Content of the video:
* the usage of the HTTP session in a Spring Boot application;
* the necessary dependencies to store the HTTP session into Redis;
* how to make an object serializable;
* how to configure the connexion between Spring Boot and Redis.
Repository: github.com/ser...
My NEW eBook: sergiolema.dev...
Blog: bit.ly/47ornJL
LinkedIn: bit.ly/41Nn61q
Facebook: bit.ly/47rc9nh
Boost your APIs with API Monitor: bit.ly/4d7C0ny
Icons:
* Ghost by AomAm from the Noun Project
* application by Pascal Heß from the Noun Project
* User by Star and Anchor Design from the Noun Project
* cookies by Hai Studio from the Noun Project
* file storage by art shop from the Noun Project
* done by Acharyas from the Noun Project
* Document by arjuazka from the Noun Project
* shopping basket by shuai tawf from the Noun Project
* database by AomAm from the Noun Project
* fast by Gregor Cresnar from the Noun Project

Пікірлер: 35

  • @dongxuandanh573
    @dongxuandanh5732 жыл бұрын

    I really like the knowledge you have shared, you have given me programming inspiration. Thank you very much, hope you will make more videos.

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    I'm happy to ear that. Thank you

  • @ErYdrian
    @ErYdrian Жыл бұрын

    Muchas gracias por tu video Sergio, justo necesitaba esta validación en redis en mi trabajo y con tu video logré implementar la parte que me faltaba, eres un crack

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    Жыл бұрын

    Gracias Erick. Encantado de que te haya servido!

  • @lts8683
    @lts8683 Жыл бұрын

    Please add more videos about best practice of a stateless application

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    Жыл бұрын

    In my new videos, I always give some tips & tricks about what I'm building, in a professional point of view.

  • @wjzz
    @wjzz3 жыл бұрын

    Awesome and to the point! Gonna use this at work ASAP :)

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    3 жыл бұрын

    Thanks!!

  • @mikyas4238
    @mikyas42382 жыл бұрын

    nicee to the point clear explanation

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    Thank you

  • @ivanovmario_5398
    @ivanovmario_53987 күн бұрын

    Thank you so much for the video. I have a problem related to storing the session information in redis. When you opened the redis cli, i noticed that the first entry is regarding the principal, but in my case it's not present. I tried logging whether spring security is creating the user and it is, but it's not persisting the principals information along with the session id and expirations in redis. Therefore when i try to fetch the sessions linked to the user i get nothing :( NOTE: i've defined the user inside the .properties file, i don't know if that's relevant.

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    5 күн бұрын

    Do you have the necessary Redis dependency in your pom.xml?

  • @seatconnect224
    @seatconnect224 Жыл бұрын

    very useful, also will be interesting to know how to manage time of storing data in redis

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    Жыл бұрын

    Thanks. Those are more advanced commands of Redis, check this link if you can find what you're looking for: redis.io/commands/expire/

  • @seatconnect224

    @seatconnect224

    Жыл бұрын

    @@TheDevWorldbySergioLema thank you, but is it possible to set expire time in spring boot app?

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    Жыл бұрын

    You can set a timeout for the session. It will be then invalidate. Use the following configuration: server.servlet.session.timeout, docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html

  • @seatconnect224

    @seatconnect224

    Жыл бұрын

    @@TheDevWorldbySergioLema got it, thanks

  • @DavisTibbz
    @DavisTibbz2 жыл бұрын

    Nice tutorial. You could also use Postman

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    Yes, but i prefer curl as it has no magic behind, i see all what i do

  • @meisj
    @meisj2 жыл бұрын

    Hi! I need help. We used Reddis for our Grails project and we applied changes on the Tomcat configuration. Upon testing, the session remains without relogin and also redirected to the other live pod however, session is terminated when the other replica pod goes up. Would you know why?

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    Does the key in Redis depend on the pod? Maybe each pod creates a new key with a new hash, this makes the session unreachable for any new pod. Try to find which key is looking at Redis.

  • @meisj

    @meisj

    2 жыл бұрын

    @@TheDevWorldbySergioLema Hi thanks for noticing me! No, because on the test, while logged in, the session remains even after deleting the pod. The session is remained to the other live pod. However it gets terminated when the replacement pod (from the other pod deleted) goes up. The weird thing is, the session is not related to this pod so I could not figure out why it gets terminated by the new respawn pod.

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    Жыл бұрын

    In those cases, you must add more logs. Which session ID is fetching your pod, which session ID is present in Redis, which session ID is present in your browser... Logs logs logs

  • @meisj

    @meisj

    Жыл бұрын

    @@TheDevWorldbySergioLema Got that I will do it today. Thanks thanks thanks!

  • @Guido-jb7oz
    @Guido-jb7oz2 жыл бұрын

    Excelente tu explicación Sergio. Todo muy claro sinceramente, me queda una duda y es si se puede limitar la cantidad de sesiones por usuario. Muchas gracias.

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    Hola, si que podrías hacerlo, pero tendría que ser directamente cuando el usuario intenta hacer un signin. Tendrías que guardar la lista de sesiones activas, y actualizarlas segun vayan caducando. Para ello tendrás que create una tabla en la base de datos, Redis no podrá ayudarte tanto en este sentido

  • @Guido-jb7oz

    @Guido-jb7oz

    2 жыл бұрын

    @@TheDevWorldbySergioLema Gracias Sergio, en mi caso solamente necesito implementar una sesión por usuario al hacer signin y denegar si intenta hacer otro signin, podría servirme tu ejemplo para mi caso?

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    Lo más sencillo sería guardar en la base de datos el estado del usuario: conectado / no-conectado. También puedes usar un contador para limitar un número de conexiones limitado (tlf, ordenador, portátil...). Para detectar si un usuario se ha deconectado, puedes vigilar constantemente la caducidad de las sesiones. El vídeo que he hecho se basa más en guardar la información de la sesión del usuario de forma que pueda compartirse con varios servidores (en caso de servicios redundantes).

  • @Guido-jb7oz

    @Guido-jb7oz

    2 жыл бұрын

    @@TheDevWorldbySergioLema Perfecto, en mi caso que solamente necesito solo 1 sesion a la vez por usuario con el estado sería suficiente. Debería usar Spring Security para las sesiones? es un proyecto con SpringBoot. Gracias!

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    Es recomendable utilizar Spring Security y se adapta bien con Spring Boot.

  • @pushpal.r.1096
    @pushpal.r.10962 жыл бұрын

    Sir getting 405 error. I am using Spring MVC + Redis. To fix RedisSerialization exception I renamed some of the session variables after this implementation only I am getting 405 error. Previously it is working. Can you please help me in solving the issue.

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    I will need more information to help you, as the stacktrace

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    Maybe post the question in stackoverflow and share the link here. I will try to answer your doubts if I can.

  • @user-iu6yz6ck6h
    @user-iu6yz6ck6h3 жыл бұрын

    Super)

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    3 жыл бұрын

    Thank you