go-redsync/redsync

Im need to use retry func for simulate native go mutex?

Closed this issue · 3 comments

Im take example, and with hightload on redis mutex I receive error lock already taken locked nodes 0 on lock or unlock.
Do I understand correctly, that I receive this error when i lock mutex/key witch already locked and I need to do something like this:

 err := retry.Do(func() error {
 	return mu.Lock()
 },
 	retry.Attempts(10))
    if err != nil {
 	panic("cannot lock")
 }

 // Do your work that requires the lock.

 err := retry.Do(func() error {
 	return mu.Unlock()
 },
 	retry.Attempts(10))
    if err != nil {
 	panic("cannot unlock")
 }

i have the same problem. I think that this doc is mot complete. Is this solution right?

	rs.NewMutex(mutexKey,
		redsync.WithExpiry(time.Second*5),
		redsync.WithTries(3),
		redsync.WithRetryDelay(time.Millisecond*100),
	)
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.