Skip to content

Can we have an example persisting the state machine with sqlalchemy or redis/valkey #508

Answered by fgmacedo
shun-liang asked this question in Q&A
Discussion options

You must be logged in to vote

For example, a quick way to only persist the current state is to implement the on_enter_state hook:

Redis persistence state machine using callback hook

Demonstrate a simple way of how to use redis to persist the current state.

This example uses the start_value constructor param and the on_enter_state callback hook.

from statemachine import State
from statemachine import StateMachine

try:
    # We try to import real redis client
    # if it fails we use a fake one only for demostration
    from redis import StrictRedis
except ImportError:

    class StrictRedis:
        """Fake redis.StrictRedis client only for demostration purposes"""

        def __init__(self, *args, **kwargs):
       …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@fgmacedo
Comment options

Answer selected by shun-liang
@fgmacedo
Comment options

@shun-liang
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants