PHP Класс izzum\statemachine\persistence\Redis

Since redis has no schemas (as a nosql db), it should store data based on the way you want to retrieve data. There will be multiple views on the data which should make sense for a lot of use cases (counters, sets, sorted sets, lists, hashes etc) to retrieve the data. All keys that izzum uses in redis can be found in this classes' constants with a 'KEY_' prefix. This class uses the php redis module and your php build should be setup with this module loaded. An instance uses a redis key prefix of 'izzum:' by default. but this can be set to whatever you like. . You can even set the prefix key to something else temporarily for loading the configuration data and then set it to another prefix for writing state data. This allows you to store multiple machine configurations under different prefixes so you can load different machines from different places, which facilitates multiple dev teams working on configuration of different machines without them overwriting other teams' definitions. The configuration of statemachines is a JSON string. The specification of the JSON string can be found in izzum\statemachine\loader\JSON::getJSONSchema. see asset/json/json.schema Internally, this class uses the JSON loader to load the configuration. It can be set up to store multiple configurations under multiple keys. You can use the normal redis connection settings to connect to redis.
Наследование: extends Adapter, implements izzum\statemachine\loader\Loader
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__call ( string $name, mixed $arguments ) : mixed very very dumb proxy to redis connection. should only be used for testing.
__construct ( string $host = '127.0.0.1', integer $port = 6379, float $timeout, string $reserved = null, integer $retry = null ) The constructor accepts default connection parameters.
__destruct ( ) do some cleanup
__toString ( )
addHistory ( Identifier $identifier, $state, $message = null, $is_exception = false ) {@inheritDoc}
getConfigurationKey ( ) : string get the configuration key used for storing a json string of machine configurations.
getEntityIds ( $machine, $state = null ) {@inheritDoc}
getPrefix ( ) : string get the prefix for all keys used
getRedis ( ) : Redis Gets a lazy loaded \Redis instance that is connected and optionally authenticated.
insertState ( Identifier $identifier, $state, $message = null ) {@inheritDoc}
isPersisted ( Identifier $identifier ) {@inheritDoc}
load ( StateMachine $statemachine ) {@inheritDoc} Load the statemachine with data from a JSON string.
processGetState ( Identifier $identifier ) {@inheritDoc}
setConfigurationKey ( string $key ) set the configuration key to be used for storing a json string of machine configurations.
setConnection ( Redis $redis ) set the redis connection explicitely, useful if you want to share the redis instance when it is created outside this class.
setDatabase ( integer $database ) set the redis database. in case there is an active connection, it switches the database.
setPassword ( string $password ) set password to authenticate to the redis server
setPrefix ( string $prefix ) set the key prefix to be used for all redis keys
setUnixDomainSocket ( $socket )
toString ( )
updateState ( Identifier $identifier, $state, $message = null ) {@inheritDoc}

Защищенные методы

Метод Описание
onConnect ( ) A hook to use in a subclass.

Описание методов

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

calls methods on a https://github.com/phpredis/phpredis instance. some method calls will only accept an array as the second argument (like hmset) This makes it useful to test the redis commands or just use this class as an interface to redis.
public __call ( string $name, mixed $arguments ) : mixed
$name string name of the method to route to the active redis connection
$arguments mixed
Результат mixed

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

You can also use an existing \Redis instance used by your application. Just construct without parameters and call 'setConnection($instance)' before doing anything else. You can also use a unix domain socket. Just construct without parameters and call 'setUnixDomainSocket' before doing anything else.
public __construct ( string $host = '127.0.0.1', integer $port = 6379, float $timeout, string $reserved = null, integer $retry = null )
$host string optional
$port integer optional
$timeout float value in seconds. default is 0 meaning unlimited
$reserved string should be NULL if $retry is specified
$retry integer value in milliseconds

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

do some cleanup
public __destruct ( )

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

public __toString ( )

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

{@inheritDoc}
public addHistory ( Identifier $identifier, $state, $message = null, $is_exception = false )
$identifier izzum\statemachine\Identifier

getConfigurationKey() закрытый публичный Метод

get the configuration key used for storing a json string of machine configurations.
final public getConfigurationKey ( ) : string
Результат string $key

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

{@inheritDoc}
public getEntityIds ( $machine, $state = null )

getPrefix() закрытый публичный Метод

get the prefix for all keys used
final public getPrefix ( ) : string
Результат string

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

Gets a lazy loaded \Redis instance that is connected and optionally authenticated.
public getRedis ( ) : Redis
Результат Redis

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

{@inheritDoc}
public insertState ( Identifier $identifier, $state, $message = null )
$identifier izzum\statemachine\Identifier

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

{@inheritDoc}
public isPersisted ( Identifier $identifier )
$identifier izzum\statemachine\Identifier

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

the JSON string is stored at the redis key 'configuration' by default. you can alter the configuration key by using Redis::setPrefix() and Redis::setConfigurationKey() First, the key ':configuration:' is checked for existence. If it exists, take the configuration from that key, else take the configuration form the ':configuration' key. This method can be overriden in a subclass to use another loader when the data is stored in redis in YAML or XML form for example. You could use the ReaderWriterDelegator to use another source to load the configuration from.
public load ( StateMachine $statemachine )
$statemachine izzum\statemachine\StateMachine

onConnect() защищенный Метод

you can do you initial setup here if you like.
protected onConnect ( )

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

{@inheritDoc}
public processGetState ( Identifier $identifier )
$identifier izzum\statemachine\Identifier

setConfigurationKey() закрытый публичный Метод

set the configuration key to be used for storing a json string of machine configurations.
final public setConfigurationKey ( string $key )
$key string

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

set the redis connection explicitely, useful if you want to share the redis instance when it is created outside this class.
public setConnection ( Redis $redis )
$redis Redis a connected (and authenticated) redis instance

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

set the redis database. in case there is an active connection, it switches the database.
public setDatabase ( integer $database )
$database integer a redis database is an integer starting from 0 (the default)

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

set password to authenticate to the redis server
public setPassword ( string $password )
$password string

setPrefix() закрытый публичный Метод

set the key prefix to be used for all redis keys
final public setPrefix ( string $prefix )
$prefix string

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

public setUnixDomainSocket ( $socket )

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

public toString ( )

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

{@inheritDoc}
public updateState ( Identifier $identifier, $state, $message = null )
$identifier izzum\statemachine\Identifier