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
파일 보기 프로젝트 열기: rolfvreijdenberger/izzum-statemachine 1 사용 예제들

공개 메소드들

메소드 설명
__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