// 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.
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.
// 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 .
func (c *MemcachedLock) TryAcquireLock(correlationId string, key string, ttl int64) (result bool, err error) {
	state, err := c.checkOpened(correlationId)
	if !state {
		return false, err
	}
	lifetimeInSec := ttl / 1000
	item := memcache.Item{
		Key:        key,
		Value:      []byte("lock"),
		Expiration: int32(lifetimeInSec),
	}
	err = c.client.Add(&item)
	if err != nil && err == memcache.ErrNotStored {
		return false, nil
	}
	return err == nil, err
}
func ( c * MemcachedLock ) TryAcquireLock ( correlationId string , key string , ttl int64 ) ( result bool , err error ) { state , err := c . checkOpened ( correlationId ) if ! state { return false , err } lifetimeInSec := ttl / 1000 item := memcache . Item { Key : key , Value : [ ] byte ( " " ) , Expiration : int32 ( lifetimeInSec ) , } err = c . client . Add ( & item ) if err != nil && err == memcache . ErrNotStored { return false , nil } return err == nil , err }
TryAcquireLock method are makes a single attempt to acquire a lock by its key.
TryAcquireLock method are makes a single attempt to acquire a lock by its key .