Create a persistence service mutex
Create a Redis 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.
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
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.
Introduced in R2018b