Documentation
¶
Index ¶
- Constants
- Variables
- func NormalizeKey(key *Key) ([]byte, error)
- type AcquiringError
- type BackendLockMode
- type BlockingSharedStore
- type BlockingStore
- type CombinedStore
- type ConsensusStrategy
- type DynamoDBStore
- type Factory
- type FileStore
- func (s *FileStore) Delete(key *Key) error
- func (s *FileStore) Exists(key *Key) (bool, error)
- func (*FileStore) PutOffExpiration(*Key, time.Duration) 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
- type 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
- type 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
- type MemcachedStore
- type MongoDBOptions
- type MongoDBStore
- type MongoSource
- type MySQLStore
- type MySQLStoreOptions
- type NoLock
- 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
- type PostgreSQLStore
- 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
- type RedisStore
- type ReleasingError
- type SQLErrorMode
- type SQLPlatform
- type SQLSchema
- type SQLStore
- type SQLStoreOptions
- type SemaphoreStore
- 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
- type SharedStore
- type Store
- type StoreBackendKind
- type 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
- type UnanimousStrategy
- type ZooKeeperOptions
- type ZooKeeperStore
Constants ¶
View Source
const DefaultTTL = 300 * time.Second
Variables ¶
View Source
var ( ErrLockConflicted = errors.New("lock acquired by other owner") ErrLockExpired = errors.New("lock expired") ErrInvalidTTL = errors.New("invalid lock TTL") ErrUnserializableKey = errors.New("key cannot be serialized") ErrUnsupportedStore = errors.New("unsupported lock store") ErrTableNotFound = errors.New("lock table not found") )
Functions ¶
func NormalizeKey ¶
Types ¶
type AcquiringError ¶
func (*AcquiringError) Error ¶
func (e *AcquiringError) Error() string
func (*AcquiringError) Unwrap ¶
func (e *AcquiringError) Unwrap() error
type BackendLockMode ¶
type BackendLockMode uint8
const ( BackendWrite BackendLockMode = iota BackendRead )
type BlockingSharedStore ¶
type BlockingSharedStore interface {
SharedStore
BlockingStore
}
type BlockingStore ¶
type CombinedStore ¶
type CombinedStore struct {
// contains filtered or unexported fields
}
func NewCombinedStore ¶
func NewCombinedStore(stores []Store, strategy Strategy) (*CombinedStore, error)
func (*CombinedStore) Delete ¶
func (s *CombinedStore) Delete(key *Key) error
func (*CombinedStore) PutOffExpiration ¶
func (s *CombinedStore) PutOffExpiration(key *Key, ttl time.Duration) error
func (*CombinedStore) Save ¶
func (s *CombinedStore) Save(key *Key) error
func (*CombinedStore) SaveRead ¶
func (s *CombinedStore) SaveRead(key *Key) error
type ConsensusStrategy ¶
type ConsensusStrategy struct{}
func (ConsensusStrategy) CanBeMet ¶
func (ConsensusStrategy) CanBeMet(failures, total int) bool
func (ConsensusStrategy) IsMet ¶
func (ConsensusStrategy) IsMet(successes, total int) bool
type DynamoDBStore ¶
type DynamoDBStore struct {
// contains filtered or unexported fields
}
func NewDynamoDBStore ¶
func NewDynamoDBStore(backend LeaseBackend, defaultTTL time.Duration) (*DynamoDBStore, error)
func (*DynamoDBStore) Delete ¶
func (s *DynamoDBStore) Delete(key *Key) error
func (*DynamoDBStore) PutOffExpiration ¶
func (s *DynamoDBStore) PutOffExpiration(key *Key, ttl time.Duration) error
func (*DynamoDBStore) Save ¶
func (s *DynamoDBStore) Save(key *Key) error
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
func NewFactory ¶
func (*Factory) CreateDefault ¶
type FileStore ¶
type FileStore struct {
// contains filtered or unexported fields
}
func NewFileStore ¶
func (*FileStore) WaitAndSave ¶
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore keeps process-local locks. A store instance owns its own lock namespace, so independently constructed stores do not share locks.
func NewInMemoryStore ¶
func NewInMemoryStore() *InMemoryStore
func (*InMemoryStore) Delete ¶
func (s *InMemoryStore) Delete(key *Key) error
func (*InMemoryStore) PutOffExpiration ¶
func (*InMemoryStore) PutOffExpiration(*Key, time.Duration) error
func (*InMemoryStore) Save ¶
func (s *InMemoryStore) Save(key *Key) error
func (*InMemoryStore) SaveRead ¶
func (s *InMemoryStore) SaveRead(key *Key) error
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
func DenormalizeKey ¶
func (*Key) MarkUnserializable ¶
func (k *Key) MarkUnserializable()
func (*Key) MarshalBinary ¶
func (*Key) ReduceLifetime ¶
func (*Key) RemoveState ¶
func (*Key) ResetLifetime ¶
func (k *Key) ResetLifetime()
func (*Key) UnmarshalBinary ¶
type LeaseBackend ¶
type LeaseBackend interface {
Acquire(ctx context.Context, resource, token string, mode BackendLockMode, ttl time.Duration, blocking bool) error
Delete(ctx context.Context, resource, token string) error
Exists(ctx context.Context, resource, token string) (bool, error)
Refresh(ctx context.Context, resource, token string, ttl time.Duration) error
}
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
func (*Lock) AcquireRead ¶
func (*Lock) IsAcquired ¶
type MemcachedStore ¶
type MemcachedStore struct {
// contains filtered or unexported fields
}
func NewMemcachedStore ¶
func NewMemcachedStore(backend LeaseBackend, defaultTTL time.Duration) (*MemcachedStore, error)
func (*MemcachedStore) Delete ¶
func (s *MemcachedStore) Delete(key *Key) error
func (*MemcachedStore) PutOffExpiration ¶
func (s *MemcachedStore) PutOffExpiration(key *Key, ttl time.Duration) error
func (*MemcachedStore) Save ¶
func (s *MemcachedStore) Save(key *Key) error
type MongoDBOptions ¶
type MongoDBOptions struct {
URI string
Database string
Collection string
DefaultTTL time.Duration
Source MongoSource
}
func ParseMongoDBStoreDSN ¶
func ParseMongoDBStoreDSN(uri string, options MongoDBOptions) (MongoDBOptions, error)
type MongoDBStore ¶
type MongoDBStore struct {
// contains filtered or unexported fields
}
func NewMongoDBStore ¶
func NewMongoDBStore(backend LeaseBackend, options MongoDBOptions) (*MongoDBStore, error)
func (*MongoDBStore) CreateTTLIndex ¶
func (s *MongoDBStore) CreateTTLIndex(ctx context.Context) error
func (*MongoDBStore) Delete ¶
func (s *MongoDBStore) Delete(key *Key) error
func (*MongoDBStore) PutOffExpiration ¶
func (s *MongoDBStore) PutOffExpiration(key *Key, ttl time.Duration) error
func (*MongoDBStore) Save ¶
func (s *MongoDBStore) Save(key *Key) error
type MongoSource ¶
type MongoSource uint8
const ( MongoSourceClient MongoSource = iota MongoSourceDatabase MongoSourceCollection )
type MySQLStore ¶
type MySQLStore struct {
// contains filtered or unexported fields
}
func NewMySQLStore ¶
func NewMySQLStore(backend LeaseBackend, options MySQLStoreOptions) (*MySQLStore, error)
func (*MySQLStore) Delete ¶
func (s *MySQLStore) Delete(key *Key) error
func (*MySQLStore) PutOffExpiration ¶
func (s *MySQLStore) PutOffExpiration(key *Key, ttl time.Duration) error
func (*MySQLStore) Save ¶
func (s *MySQLStore) Save(key *Key) error
func (*MySQLStore) WaitAndSave ¶
func (s *MySQLStore) WaitAndSave(ctx context.Context, key *Key) error
type MySQLStoreOptions ¶
type MySQLStoreOptions struct {
Driver string
ErrorMode SQLErrorMode
ServerVersion string
StringifyResults bool
NativePreparedStatements bool
}
func ParseMySQLStoreDSN ¶
func ParseMySQLStoreDSN(dsn string) (MySQLStoreOptions, error)
type PostgreSQLStore ¶
type PostgreSQLStore struct {
// contains filtered or unexported fields
}
func NewPostgreSQLStore ¶
func NewPostgreSQLStore(backend LeaseBackend, options PostgreSQLStoreOptions) (*PostgreSQLStore, error)
func (*PostgreSQLStore) Delete ¶
func (s *PostgreSQLStore) Delete(key *Key) error
func (*PostgreSQLStore) PutOffExpiration ¶
func (s *PostgreSQLStore) PutOffExpiration(key *Key, ttl time.Duration) error
func (*PostgreSQLStore) Save ¶
func (s *PostgreSQLStore) Save(key *Key) error
func (*PostgreSQLStore) SaveRead ¶
func (s *PostgreSQLStore) SaveRead(key *Key) error
func (*PostgreSQLStore) WaitAndSave ¶
func (s *PostgreSQLStore) WaitAndSave(ctx context.Context, key *Key) error
func (*PostgreSQLStore) WaitAndSaveRead ¶
func (s *PostgreSQLStore) WaitAndSaveRead(ctx context.Context, key *Key) error
type PostgreSQLStoreOptions ¶
type PostgreSQLStoreOptions struct{ Driver string }
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
func NewRedisStore ¶
func NewRedisStore(backend LeaseBackend, defaultTTL time.Duration) (*RedisStore, error)
func (*RedisStore) Delete ¶
func (s *RedisStore) Delete(key *Key) error
func (*RedisStore) PutOffExpiration ¶
func (s *RedisStore) PutOffExpiration(key *Key, ttl time.Duration) error
func (*RedisStore) Save ¶
func (s *RedisStore) Save(key *Key) error
func (*RedisStore) SaveRead ¶
func (s *RedisStore) SaveRead(key *Key) error
type ReleasingError ¶
func (*ReleasingError) Error ¶
func (e *ReleasingError) Error() string
func (*ReleasingError) Unwrap ¶
func (e *ReleasingError) Unwrap() error
type SQLErrorMode ¶
type SQLErrorMode uint8
const ( SQLErrorModeException SQLErrorMode = iota SQLErrorModeSilent )
type SQLPlatform ¶
type SQLPlatform uint8
const ( SQLPlatformSQLite SQLPlatform = iota SQLPlatformPostgreSQL SQLPlatformMySQL SQLPlatformMariaDB )
type SQLSchema ¶
type SQLSchema struct {
// contains filtered or unexported fields
}
func NewSQLSchema ¶
func NewSQLSchema() *SQLSchema
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
func NewSQLStore ¶
func NewSQLStore(backend LeaseBackend, options SQLStoreOptions) (*SQLStore, error)
func (*SQLStore) ConfigureSchema ¶
func (*SQLStore) PutOffExpiration ¶
type SQLStoreOptions ¶
func ParseSQLStoreDSN ¶
func ParseSQLStoreDSN(dsn string) (SQLStoreOptions, error)
type SemaphoreStore ¶
type SemaphoreStore struct {
// contains filtered or unexported fields
}
func NewSemaphoreStore ¶
func NewSemaphoreStore(projectID string, backend LeaseBackend) (*SemaphoreStore, error)
func (*SemaphoreStore) Delete ¶
func (s *SemaphoreStore) Delete(key *Key) error
func (*SemaphoreStore) ProjectID ¶
func (s *SemaphoreStore) ProjectID() string
func (*SemaphoreStore) PutOffExpiration ¶
func (s *SemaphoreStore) PutOffExpiration(key *Key, ttl time.Duration) error
func (*SemaphoreStore) Save ¶
func (s *SemaphoreStore) Save(key *Key) error
func (*SemaphoreStore) WaitAndSave ¶
func (s *SemaphoreStore) WaitAndSave(ctx context.Context, key *Key) error
type SharedLocker ¶
type SharedLocker interface {
Locker
}
type SharedStore ¶
type SharedStore interface {
Store
}
type Store ¶
type StoreBackendKind ¶
type StoreBackendKind uint8
const ( StoreBackendRedis StoreBackendKind = iota StoreBackendMemcached StoreBackendRedisProxy )
type StoreFactory ¶
type StoreFactory struct {
// contains filtered or unexported fields
}
func NewStoreFactory ¶
func NewStoreFactory(backend LeaseBackend) *StoreFactory
func (*StoreFactory) FromBackend ¶
func (f *StoreFactory) FromBackend(kind StoreBackendKind, advisory bool) (Store, error)
func (*StoreFactory) FromSQLDriver ¶
func (f *StoreFactory) FromSQLDriver(driver string, advisory bool) (Store, error)
func (*StoreFactory) FromSQLPlatform ¶
func (f *StoreFactory) FromSQLPlatform(platform SQLPlatform, version string, advisory bool) (Store, error)
type UnanimousStrategy ¶
type UnanimousStrategy struct{}
func (UnanimousStrategy) CanBeMet ¶
func (UnanimousStrategy) CanBeMet(failures, _ int) bool
func (UnanimousStrategy) IsMet ¶
func (UnanimousStrategy) IsMet(successes, total int) bool
type ZooKeeperOptions ¶
func ParseZooKeeperDSN ¶
func ParseZooKeeperDSN(dsn string) (ZooKeeperOptions, error)
type ZooKeeperStore ¶
type ZooKeeperStore struct {
// contains filtered or unexported fields
}
func NewZooKeeperStore ¶
func NewZooKeeperStore(backend LeaseBackend, root string) (*ZooKeeperStore, error)
func (*ZooKeeperStore) Delete ¶
func (s *ZooKeeperStore) Delete(key *Key) error
func (*ZooKeeperStore) PutOffExpiration ¶
func (s *ZooKeeperStore) PutOffExpiration(key *Key, ttl time.Duration) error
func (*ZooKeeperStore) Save ¶
func (s *ZooKeeperStore) Save(key *Key) error
Click to show internal directories.
Click to hide internal directories.