izzum\statemachine\persistence\Redis::updateState PHP Метод

updateState() публичный Метод

{@inheritDoc}
public updateState ( Identifier $identifier, $state, $message = null )
$identifier izzum\statemachine\Identifier
    public function updateState(Identifier $identifier, $state, $message = null)
    {
        $redis = $this->getRedis();
        try {
            //first, get the current state
            $key = sprintf(self::KEY_ENTITY_STATE, $identifier->getMachine(), $identifier->getEntityId());
            $current = $redis->get($key);
            //now that we have the current state, start multi in pipeline mode for faster execution (single server roundtrip)
            $redis->multi(\Redis::PIPELINE);
            //remove from current state set
            $key = sprintf(self::KEY_CURRENT_STATES, $identifier->getMachine(), $current);
            $redis->srem($key, $identifier->getEntityId());
            //set the new state
            $key = sprintf(self::KEY_ENTITY_STATE, $identifier->getMachine(), $identifier->getEntityId());
            $redis->set($key, $state);
            //set on current states set
            $key = sprintf(self::KEY_CURRENT_STATES, $identifier->getMachine(), $state);
            $redis->sadd($key, $identifier->getEntityId());
            //execute the sequence of redis commands
            $redis->exec();
        } catch (\Exception $e) {
            $redis->discard();
            throw new Exception(sprintf('updating state failed: [%s]', $e->getMessage()), Exception::PERSISTENCE_LAYER_EXCEPTION);
        }
    }