Create a persistence service mutex
First, create a persistence service controller object and use that object to start the persistence service.
ctrl = mps.cache.control('myRedisConnection','Redis','Port',4519); start(ctrl)
Use the connection name to create a persistence service mutex.
lk = mps.sync.mutex('myMutex','Connection','myRedisConnection')
lk = TimedRedisMutex with properties: Expiration: 10 ConnectionName: 'myRedisConnection' MutexName: 'myMutex'
mutexName— Mutex name
Name of persistence service mutex, specified as a character vector.
connectionName— Name of connection
Name of connection to persistence service, specified as a character vector.
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
'Expiration'— Time in seconds
Expiration time in seconds after the lock is acquired.
Other clients will be able to acquire the lock even if you do not release it.
A persistence service mutex allows multiple clients to take turns using a shared resource. Each cooperating client creates a mutex object with the same name using a connection to a shared persistence service. To gain exclusive access to the shared resource, a client attempts to acquire a lock on the mutex. When the client finishes operating on the shared resource, it releases the lock. To prevent lockouts should the locking client crash, all locks expire after a certain amount of time.
Acquiring a lock on a mutex prevents other clients from acquiring a lock on that mutex but it does not lock the persistence service or any keys or values stored in the persistence service. These locks are advisory only and are meant to be used by cooperating clients intent of preventing data corruption. Rogue clients will be able to corrupt or delete data if they do not voluntarily respect the mutex locks.