Documentation
¶
Index ¶
- type EventKind
- type Map
- func (sm *Map) AppendUniqueValues(ctx context.Context, key string, items ...string) ([]string, error)
- func (sm *Map) AppendValues(ctx context.Context, key string, items ...string) ([]string, error)
- func (sm *Map) Close()
- func (sm *Map) Delete(ctx context.Context, key string) (string, error)
- func (sm *Map) Get(key string) (string, bool)
- func (sm *Map) GetValues(key string) ([]string, bool)
- func (sm *Map) Inc(ctx context.Context, key string, delta int) (int, error)
- func (sm *Map) Keys() []string
- func (sm *Map) Len() int
- func (sm *Map) Map() map[string]string
- func (sm *Map) RemoveValues(ctx context.Context, key string, items ...string) ([]string, error)
- func (sm *Map) Reset(ctx context.Context) error
- func (sm *Map) Set(ctx context.Context, key, value string) (string, error)
- func (sm *Map) SetAndWait(ctx context.Context, key, value string) (string, error)
- func (sm *Map) Subscribe() <-chan EventKind
- func (sm *Map) TestAndDelete(ctx context.Context, key, test string) (string, error)
- func (sm *Map) TestAndReset(ctx context.Context, keys, tests []string) (bool, error)
- func (sm *Map) TestAndSet(ctx context.Context, key, test, value string) (string, error)
- func (sm *Map) Unsubscribe(c <-chan EventKind)
- type MapOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map struct { Name string // contains filtered or unexported fields }
Map is a replicated map that emits events when elements change. Multiple processes can join the same replicated map and update it.
func Join ¶
Join retrieves the content of the replicated map with the given name and subscribes to updates. The local content is eventually consistent across all nodes that join the replicated map with the same name.
Clients can call the Map method on the returned Map to retrieve a copy of its content and subscribe to its C channel to receive updates when the content changes (note that multiple remote changes may result in a single notification). The returned Map is safe for concurrent use.
Clients should call Close before exiting to stop updates and release resources resulting in a read-only point-in-time copy.
func (*Map) AppendUniqueValues ¶ added in v1.0.0
func (sm *Map) AppendUniqueValues(ctx context.Context, key string, items ...string) ([]string, error)
AppendUniqueValues appends the given items to the value for the given key if they are not already present and returns the result. The array of items is stored as a comma-separated list (so items should not have commas in them). An error is returned if the key is empty or contains an equal sign.
func (*Map) AppendValues ¶
AppendValues appends the given items to the value for the given key and returns the result. The array of items is stored as a comma-separated list (so items should not have commas in them). An error is returned if the key is empty or contains an equal sign.
func (*Map) Close ¶
func (sm *Map) Close()
Close closes the connection to the map, freeing resources. It is safe to call Close multiple times.
func (*Map) GetValues ¶ added in v1.0.0
GetValues returns the comma separated values for the given key. This is a convenience method intended to be used in conjunction with AppendValues and RemoveValues.
func (*Map) Inc ¶
Inc increments the value for the given key and returns the result, the value must represent an integer. An error is returned if the key is empty, contains an equal sign or if the value does not represent an integer.
func (*Map) RemoveValues ¶
RemoveValues removes the given items from the value for the given key and returns the result. The array of items is stored as a comma-separated list. If the removal results in an empty slice then the key is automatically deleted. An error is returned if key is empty or contains an equal sign.
func (*Map) Set ¶
Set sets the value for the given key and returns the previous value. An error is returned if the key is empty or contains an equal sign.
func (*Map) SetAndWait ¶
SetAndWait is a convenience method that calls Set and then waits for the update to be applied and the notification to be sent.
func (*Map) Subscribe ¶
Subscribe returns a channel that receives notifications when the map changes. The channel is closed when the map is stopped. This channel simply notifies that the map has changed, it does not provide the actual changes, instead the Map method should be used to read the current content. This allows the notification to be sent without blocking. Multiple remote updates may result in a single notification. Subscribe returns nil if the map is stopped.
func (*Map) TestAndDelete ¶ added in v1.0.0
TestAndDelete tests that the value for the given key matches the test value and deletes the key if it does.
func (*Map) TestAndReset ¶ added in v1.0.0
TestAndReset tests that the values for the given keys match the test values and clears the map if they do.
func (*Map) TestAndSet ¶ added in v0.0.3
TestAndSet sets the value for the given key if the current value matches the given test value. The previous value is returned. An error is returned if the key is empty or contains an equal sign.
func (*Map) Unsubscribe ¶
Unsubscribe removes the given channel from the list of subscribers and closes it.