ReplicatedMap

class ReplicatedMap(client, service_name, name)

Bases: hazelcast.proxy.base.Proxy

A ReplicatedMap is a map-like data structure with weak consistency and values locally stored on every node of the cluster.

Whenever a value is written asynchronously, the new value will be internally distributed to all existing cluster members, and eventually every node will have the new value.

When a new node joins the cluster, the new node initially will request existing values from older nodes and replicate them locally.

add_entry_listener(key=None, predicate=None, added_func=None, removed_func=None, updated_func=None, evicted_func=None, clear_all_func=None)

Adds a continuous entry listener for this map. Listener will get notified for map events filtered with given parameters.

Parameters:
  • key – (object), key for filtering the events (optional).
  • predicate – (Predicate), predicate for filtering the events (optional).
  • added_func – Function to be called when an entry is added to map (optional).
  • removed_func – Function to be called when an entry is removed from map (optional).
  • updated_func – Function to be called when an entry is updated (optional).
  • evicted_func – Function to be called when an entry is evicted from map (optional).
  • clear_all_func – Function to be called when entries are cleared from map (optional).
Returns:

(str), a registration id which is used as a key to remove the listener.

See also

Predicate for more info about predicates.

clear()

Wipes data out of the replicated map.

contains_key(key)

Determines whether this map contains an entry with the key.

Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters:key – (object), the specified key.
Returns:(bool), true if this map contains an entry for the specified key.
contains_value(value)

Determines whether this map contains one or more keys for the specified value.

Parameters:value – (object), the specified value.
Returns:(bool), true if this map contains an entry for the specified value.
entry_set()

Returns a List clone of the mappings contained in this map.

Warning: The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.

Returns:(Sequence), the list of key-value tuples in the map.
get(key)

Returns the value for the specified key, or None if this map does not contain this key.

Warning: This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key’s class.

Parameters:key – (object), the specified key.
Returns:(Sequence), the list of the values associated with the specified key.
is_empty()

Returns true if this map contains no key-value mappings.

Returns:(bool), true if this map contains no key-value mappings.
key_set()

Returns the list of keys in the ReplicatedMap.

Warning: The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.

Returns:(Sequence), a list of the clone of the keys.
put(key, value, ttl=0)

Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced by the specified value. If ttl is provided, entry will expire and get evicted after the ttl.

Parameters:
  • key – (object), the specified key.
  • value – (object), the value to associate with the key.
  • ttl – (int), maximum time in seconds for this entry to stay, if not provided, the value configured on server side configuration will be used(optional).
Returns:

(object), previous value associated with key or None if there was no mapping for key.

put_all(map)

Copies all of the mappings from the specified map to this map. No atomicity guarantees are given. In the case of a failure, some of the key-value tuples may get written, while others are not.

Parameters:map – (dict), map which includes mappings to be stored in this map.
remove(key)

Removes the mapping for a key from this map if it is present. The map will not contain a mapping for the specified key once the call returns.

Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters:key – (object), key of the mapping to be deleted.
Returns:(object), the previous value associated with key, or None if there was no mapping for key.
remove_entry_listener(registration_id)

Removes the specified entry listener. Returns silently if there is no such listener added before.

Parameters:registration_id – (str), id of registered listener.
Returns:(bool), true if registration is removed, false otherwise.
size()

Returns the number of entries in this multimap.

Returns:(int), number of entries in this multimap.
values()

Returns the list of values in the map.

Warning: The returned list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.

Returns:(Sequence), the list of values in the map.