lock

package
Version: v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemcachedLock

type MemcachedLock struct {
	*clock.Lock
	// contains filtered or unexported fields
}

MemcachedLock are distributed lock that implemented based on Memcaches caching service.

The current implementation does not support authentication.

Configuration parameters:

- connection(s):

  • discovery_key: (optional) a key to retrieve the connection from IDiscovery
  • host: host name or IP address
  • port: port number
  • uri: resource URI or connection string with all parameters in it

- options:

  • max_size: maximum number of values stored in this cache (default: 1000)
  • max_key_size: maximum key length (default: 250)
  • max_expiration: maximum expiration duration in milliseconds (default: 2592000)
  • max_value: maximum value length (default: 1048576)
  • pool_size: pool size (default: 5)
  • reconnect: reconnection timeout in milliseconds (default: 10 sec)
  • retries: number of retries (default: 3)
  • timeout: default caching timeout in milliseconds (default: 1 minute)
  • failures: number of failures before stop retrying (default: 5)
  • retry: retry timeout in milliseconds (default: 30 sec)
  • idle: idle timeout before disconnect in milliseconds (default: 5 sec)

References:

- *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection

Example:

lock := NewMemcachedLock();
lock.Configure(cconf.NewConfigParamsFromTuples(
  "host", "localhost",
  "port", 11211,
));

err := lock.Open("123")
if err != nil {
  ...
}

result, err := lock.TryAcquireLock("123", "key1", 3000)
if result {
	// Processing...
}
err = lock.ReleaseLock("123", "key1")
// Continue...

func NewMemcachedLock

func NewMemcachedLock() *MemcachedLock

NewMemcachedLock method are creates a new instance of this lock.

func (*MemcachedLock) Close

func (c *MemcachedLock) Close(correlationId string) error

Close method are closes component and frees used resources. Parameters:

  • correlationId (optional) transaction id to trace execution through call chain.
  • callback callback function that receives error or nil no errors occured.

func (*MemcachedLock) Configure

func (c *MemcachedLock) Configure(config *cconf.ConfigParams)

Configure method are configures component by passing configuration parameters.

  • config configuration parameters to be set.

func (*MemcachedLock) IsOpen

func (c *MemcachedLock) IsOpen() bool

IsOpen method are checks if the component is opened. Returns: true if the component has been opened and false otherwise.

func (*MemcachedLock) Open

func (c *MemcachedLock) Open(correlationId string) error

/ Open method are opens the component. Parameters:

  • correlationId (optional) transaction id to trace execution through call chain.

Retruns: error or nil no errors occured.

func (*MemcachedLock) ReleaseLock

func (c *MemcachedLock) ReleaseLock(correlationId string, key string) error

ReleaseLock method are releases prevously acquired lock by its key.

  • correlationId (optional) transaction id to trace execution through call chain.
  • key a unique lock key to release. Returns error or nil for success.

func (*MemcachedLock) SetReferences

func (c *MemcachedLock) SetReferences(references cref.IReferences)

SetReferences method are sets references to dependent components.

  • references references to locate the component dependencies.

func (*MemcachedLock) TryAcquireLock

func (c *MemcachedLock) TryAcquireLock(correlationId string, key string, ttl int64) (result bool, err error)

TryAcquireLock method are makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result. Parameters:

  • correlationId (optional) transaction id to trace execution through call chain.
  • key a unique lock key to acquire.
  • ttl a lock timeout (time to live) in milliseconds. Returns: a lock result or error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL