0

I am using RedisStateMachinePersister for persisting StateMachine with Redis. I can store StateMachine with below code

 redisPersister.persist(mc,"1");

redisPersister is instance of RedisStateMachinePersister. I can also see in Redis termianl that some value is stored in Redis with key "1".

enter image description here

But when I try to retrieve this StateMachine with same key("1") with below code, it is not getting retrieve the StateMachine object which I have stored/persisted.

redisPersister.restore(mc2,"1");

mc2 object is not same mc object which I have persisted/stored.Any help on this would be appreciated.

Dhaval Goti
  • 447
  • 2
  • 10
  • 25

1 Answers1

0

Following the instructions from the official documentation, you will get the job done :

  1. https://docs.spring.io/spring-statemachine/docs/1.1.x/reference/html/sm-persist.html
  2. https://docs.spring.io/spring-statemachine/docs/1.1.x/reference/html/statemachine-examples-eventservice.html

Edit 2023/05/14 : It seems really strange you didn't get back the record you have stored here. Some legit questions to check while thinking about your problem context :

  1. Do you have multiple REDIS servers installed listening on various ports (with system packages managers and with docker too) ?
  2. Do you have checked your Spring datasource configuration for REDIS ?
  3. Do you use spring profiles to handle your dev/test/prod databases and your accordingly cache configs ?

Edit 2023/05/16 : Try to use any java client as jedis or lettuce to query datas from redis. It seems reading directly in-memory datas directly is not possible without using a java client, not as standard RDBMS which are allowing that

BendaThierry.com
  • 2,080
  • 1
  • 15
  • 17
  • 1
    I have done same configuration as suggested but restore of state machine doesn't work. – Dhaval Goti May 11 '23 at 13:52
  • Edited my answer to think about commons things which could lead to these kind of problem. – BendaThierry.com May 14 '23 at 12:22
  • 1. I have only one Redis server installed. 2. Yes, It is working fine as I am able to save other data in Redis 3. No, profile is not used as of now. – Dhaval Goti May 15 '23 at 05:02
  • Try to use any java client as jedis or lettuce to query datas from redis. It seems reading directly in-memory datas directly is not possible without using a java client, not as standard RDBMS which are allowing that. – BendaThierry.com May 16 '23 at 08:02
  • I have already used Jedis but except StateMachine Object, other serializable objects are stored fine but not StateMachine object. – Dhaval Goti May 17 '23 at 04:41
  • Please check you are using that config https://stackoverflow.com/a/63998307/390462 – BendaThierry.com May 18 '23 at 09:47
  • 1
    I am not using JPA persistence but I want to use redis persistence. Is this config still applicable to redis as well? – Dhaval Goti May 18 '23 at 14:01
  • hmm I am using JPA and it's working fine, try with it. If it's not working too we will check other things later on. – BendaThierry.com May 19 '23 at 10:10