SetNX Sets the given value under the specified key if no value was associated with it.
(key string, value interface{})
| 108 | |
| 109 | // SetNX Sets the given value under the specified key if no value was associated with it. |
| 110 | func (slm ShardLockMaps) SetNX(key string, value interface{}) bool { |
| 111 | shard := slm.GetShard(key) |
| 112 | shard.Lock() |
| 113 | _, ok := shard.items[key] |
| 114 | if !ok { |
| 115 | shard.items[key] = value |
| 116 | } |
| 117 | shard.Unlock() |
| 118 | return !ok |
| 119 | } |
| 120 | |
| 121 | // MSet Sets the given value under the specified key. |
| 122 | func (slm ShardLockMaps) MSet(data map[string]interface{}) { |