Versions in this module Expand all Collapse all v1 v1.0.0 Aug 27, 2026 Changes in this version + const DefaultTTL + var ErrInvalidTTL = errors.New("invalid lock TTL") + var ErrLockConflicted = errors.New("lock acquired by other owner") + var ErrLockExpired = errors.New("lock expired") + var ErrTableNotFound = errors.New("lock table not found") + var ErrUnserializableKey = errors.New("key cannot be serialized") + var ErrUnsupportedStore = errors.New("unsupported lock store") + func NormalizeKey(key *Key) ([]byte, error) + type AcquiringError struct + Err error + Resource string + func (e *AcquiringError) Error() string + func (e *AcquiringError) Unwrap() error + type BackendLockMode uint8 + const BackendRead + const BackendWrite + type BlockingSharedStore interface + WaitAndSaveRead func(context.Context, *Key) error + type BlockingStore interface + WaitAndSave func(context.Context, *Key) error + type CombinedStore struct + func NewCombinedStore(stores []Store, strategy Strategy) (*CombinedStore, error) + func (s *CombinedStore) Delete(key *Key) error + func (s *CombinedStore) Exists(key *Key) (bool, error) + func (s *CombinedStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *CombinedStore) Save(key *Key) error + func (s *CombinedStore) SaveRead(key *Key) error + type ConsensusStrategy struct + func (ConsensusStrategy) CanBeMet(failures, total int) bool + func (ConsensusStrategy) IsMet(successes, total int) bool + type DynamoDBStore struct + func NewDynamoDBStore(backend LeaseBackend, defaultTTL time.Duration) (*DynamoDBStore, error) + func (s *DynamoDBStore) Delete(key *Key) error + func (s *DynamoDBStore) Exists(key *Key) (bool, error) + func (s *DynamoDBStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *DynamoDBStore) Save(key *Key) error + type Factory struct + func NewFactory(store Store) *Factory + func (f *Factory) Create(resource string, ttl time.Duration, autoRelease bool) *Lock + func (f *Factory) CreateDefault(resource string) *Lock + func (f *Factory) CreateFromKey(key *Key, ttl time.Duration, autoRelease bool) *Lock + type FileStore struct + func NewFileStore(directory string) (*FileStore, error) + func (*FileStore) PutOffExpiration(*Key, time.Duration) error + func (s *FileStore) Delete(key *Key) error + func (s *FileStore) Exists(key *Key) (bool, error) + func (s *FileStore) Save(key *Key) error + func (s *FileStore) SaveRead(key *Key) error + func (s *FileStore) WaitAndSave(ctx context.Context, key *Key) error + func (s *FileStore) WaitAndSaveRead(ctx context.Context, key *Key) error + type InMemoryStore struct + func NewInMemoryStore() *InMemoryStore + func (*InMemoryStore) PutOffExpiration(*Key, time.Duration) error + func (s *InMemoryStore) Delete(key *Key) error + func (s *InMemoryStore) Exists(key *Key) (bool, error) + func (s *InMemoryStore) Save(key *Key) error + func (s *InMemoryStore) SaveRead(key *Key) error + type Key struct + func DecodeKey(payload []byte) (*Key, error) + func DenormalizeKey(payload []byte) (*Key, error) + func NewKey(resource string) *Key + func (k *Key) Expired() bool + func (k *Key) MarkUnserializable() + func (k *Key) MarshalBinary() ([]byte, error) + func (k *Key) ReduceLifetime(ttl time.Duration) + func (k *Key) RemainingLifetime() (time.Duration, bool) + func (k *Key) RemoveState(name string) + func (k *Key) ResetLifetime() + func (k *Key) SetState(name string, value any) + func (k *Key) State(name string) (any, bool) + func (k *Key) String() string + func (k *Key) UnmarshalBinary(payload []byte) error + type LeaseBackend interface + Acquire func(ctx context.Context, resource, token string, mode BackendLockMode, ...) error + Delete func(ctx context.Context, resource, token string) error + Exists func(ctx context.Context, resource, token string) (bool, error) + Refresh func(ctx context.Context, resource, token string, ttl time.Duration) error + type Lock struct + func NewLock(key *Key, store Store, ttl time.Duration, autoRelease bool) *Lock + func (l *Lock) Acquire(ctx context.Context, blocking bool) (bool, error) + func (l *Lock) AcquireRead(ctx context.Context, blocking bool) (bool, error) + func (l *Lock) Close() error + func (l *Lock) Expired() bool + func (l *Lock) IsAcquired() (bool, error) + func (l *Lock) Refresh(ttl time.Duration) error + func (l *Lock) Release() error + func (l *Lock) RemainingLifetime() (time.Duration, bool) + func (l *Lock) SetLogger(logger *slog.Logger) + type Locker interface + Acquire func(context.Context, bool) (bool, error) + Expired func() bool + IsAcquired func() (bool, error) + Refresh func(time.Duration) error + Release func() error + RemainingLifetime func() (time.Duration, bool) + type MemcachedStore struct + func NewMemcachedStore(backend LeaseBackend, defaultTTL time.Duration) (*MemcachedStore, error) + func (s *MemcachedStore) Delete(key *Key) error + func (s *MemcachedStore) Exists(key *Key) (bool, error) + func (s *MemcachedStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *MemcachedStore) Save(key *Key) error + type MongoDBOptions struct + Collection string + Database string + DefaultTTL time.Duration + Source MongoSource + URI string + func ParseMongoDBStoreDSN(uri string, options MongoDBOptions) (MongoDBOptions, error) + type MongoDBStore struct + func NewMongoDBStore(backend LeaseBackend, options MongoDBOptions) (*MongoDBStore, error) + func (s *MongoDBStore) CreateTTLIndex(ctx context.Context) error + func (s *MongoDBStore) Delete(key *Key) error + func (s *MongoDBStore) Exists(key *Key) (bool, error) + func (s *MongoDBStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *MongoDBStore) Save(key *Key) error + type MongoSource uint8 + const MongoSourceClient + const MongoSourceCollection + const MongoSourceDatabase + type MySQLStore struct + func NewMySQLStore(backend LeaseBackend, options MySQLStoreOptions) (*MySQLStore, error) + func (s *MySQLStore) Delete(key *Key) error + func (s *MySQLStore) Exists(key *Key) (bool, error) + func (s *MySQLStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *MySQLStore) Save(key *Key) error + func (s *MySQLStore) WaitAndSave(ctx context.Context, key *Key) error + type MySQLStoreOptions struct + Driver string + ErrorMode SQLErrorMode + NativePreparedStatements bool + ServerVersion string + StringifyResults bool + func ParseMySQLStoreDSN(dsn string) (MySQLStoreOptions, error) + type NoLock struct + func (NoLock) Acquire(context.Context, bool) (bool, error) + func (NoLock) AcquireRead(context.Context, bool) (bool, error) + func (NoLock) Close() error + func (NoLock) Expired() bool + func (NoLock) IsAcquired() (bool, error) + func (NoLock) Refresh(time.Duration) error + func (NoLock) Release() error + func (NoLock) RemainingLifetime() (time.Duration, bool) + type NullStore struct + func NewNullStore() *NullStore + func (*NullStore) Delete(*Key) error + func (*NullStore) Exists(*Key) (bool, error) + func (*NullStore) PutOffExpiration(*Key, time.Duration) error + func (*NullStore) Save(*Key) error + func (*NullStore) SaveRead(*Key) error + type PostgreSQLStore struct + func NewPostgreSQLStore(backend LeaseBackend, options PostgreSQLStoreOptions) (*PostgreSQLStore, error) + func (s *PostgreSQLStore) Delete(key *Key) error + func (s *PostgreSQLStore) Exists(key *Key) (bool, error) + func (s *PostgreSQLStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *PostgreSQLStore) Save(key *Key) error + func (s *PostgreSQLStore) SaveRead(key *Key) error + func (s *PostgreSQLStore) WaitAndSave(ctx context.Context, key *Key) error + func (s *PostgreSQLStore) WaitAndSaveRead(ctx context.Context, key *Key) error + type PostgreSQLStoreOptions struct + Driver string + type RedisStore struct + func NewRedisStore(backend LeaseBackend, defaultTTL time.Duration) (*RedisStore, error) + func (s *RedisStore) Delete(key *Key) error + func (s *RedisStore) Exists(key *Key) (bool, error) + func (s *RedisStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *RedisStore) Save(key *Key) error + func (s *RedisStore) SaveRead(key *Key) error + type ReleasingError struct + Err error + Resource string + func (e *ReleasingError) Error() string + func (e *ReleasingError) Unwrap() error + type SQLErrorMode uint8 + const SQLErrorModeException + const SQLErrorModeSilent + type SQLPlatform uint8 + const SQLPlatformMariaDB + const SQLPlatformMySQL + const SQLPlatformPostgreSQL + const SQLPlatformSQLite + type SQLSchema struct + func NewSQLSchema() *SQLSchema + func (s *SQLSchema) AddTable(name string, columns []string) + func (s *SQLSchema) Columns(name string) []string + func (s *SQLSchema) HasTable(name string) bool + type SQLStore struct + func NewSQLStore(backend LeaseBackend, options SQLStoreOptions) (*SQLStore, error) + func (*SQLStore) ConfigureSchema(schema *SQLSchema, sameDatabase func() bool) + func (s *SQLStore) Delete(key *Key) error + func (s *SQLStore) Exists(key *Key) (bool, error) + func (s *SQLStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *SQLStore) Save(key *Key) error + type SQLStoreOptions struct + DefaultTTL time.Duration + Dialect string + Transactional bool + func ParseSQLStoreDSN(dsn string) (SQLStoreOptions, error) + type SemaphoreStore struct + func NewSemaphoreStore(projectID string, backend LeaseBackend) (*SemaphoreStore, error) + func (s *SemaphoreStore) Delete(key *Key) error + func (s *SemaphoreStore) Exists(key *Key) (bool, error) + func (s *SemaphoreStore) ProjectID() string + func (s *SemaphoreStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *SemaphoreStore) Save(key *Key) error + func (s *SemaphoreStore) WaitAndSave(ctx context.Context, key *Key) error + type SharedLocker interface + AcquireRead func(context.Context, bool) (bool, error) + type SharedStore interface + SaveRead func(*Key) error + type Store interface + Delete func(*Key) error + Exists func(*Key) (bool, error) + PutOffExpiration func(*Key, time.Duration) error + Save func(*Key) error + func OpenStore(dsn string) (Store, error) + type StoreBackendKind uint8 + const StoreBackendMemcached + const StoreBackendRedis + const StoreBackendRedisProxy + type StoreFactory struct + func NewStoreFactory(backend LeaseBackend) *StoreFactory + func (f *StoreFactory) FromBackend(kind StoreBackendKind, advisory bool) (Store, error) + func (f *StoreFactory) FromSQLDriver(driver string, advisory bool) (Store, error) + func (f *StoreFactory) FromSQLPlatform(platform SQLPlatform, version string, advisory bool) (Store, error) + func (f *StoreFactory) Open(dsn string) (Store, error) + type Strategy interface + CanBeMet func(failures, total int) bool + IsMet func(successes, total int) bool + type UnanimousStrategy struct + func (UnanimousStrategy) CanBeMet(failures, _ int) bool + func (UnanimousStrategy) IsMet(successes, total int) bool + type ZooKeeperOptions struct + Path string + Servers []string + func ParseZooKeeperDSN(dsn string) (ZooKeeperOptions, error) + type ZooKeeperStore struct + func NewZooKeeperStore(backend LeaseBackend, root string) (*ZooKeeperStore, error) + func (s *ZooKeeperStore) Delete(key *Key) error + func (s *ZooKeeperStore) Exists(key *Key) (bool, error) + func (s *ZooKeeperStore) PutOffExpiration(key *Key, ttl time.Duration) error + func (s *ZooKeeperStore) Save(key *Key) error