|
3 | 3 | from hazelcast.future import combine_futures, ImmediateFuture |
4 | 4 | from hazelcast.near_cache import NearCache |
5 | 5 | from hazelcast.protocol.codec import map_add_entry_listener_codec, map_add_entry_listener_to_key_codec, \ |
6 | | - map_add_entry_listener_with_predicate_codec, map_add_entry_listener_to_key_with_predicate_codec, \ |
7 | | - map_add_index_codec, map_clear_codec, map_contains_key_codec, map_contains_value_codec, map_delete_codec, \ |
8 | | - map_entry_set_codec, map_entries_with_predicate_codec, map_evict_codec, map_evict_all_codec, map_flush_codec, \ |
9 | | - map_force_unlock_codec, map_get_codec, map_get_all_codec, map_get_entry_view_codec, map_is_empty_codec, \ |
10 | | - map_is_locked_codec, map_key_set_codec, map_key_set_with_predicate_codec, map_load_all_codec, \ |
11 | | - map_load_given_keys_codec, map_lock_codec, map_put_codec, map_put_all_codec, map_put_if_absent_codec, \ |
12 | | - map_put_transient_codec, map_size_codec, map_remove_codec, map_remove_if_same_codec, \ |
13 | | - map_remove_entry_listener_codec, map_replace_codec, map_replace_if_same_codec, map_set_codec, map_try_lock_codec, \ |
14 | | - map_try_put_codec, map_try_remove_codec, map_unlock_codec, map_values_codec, map_values_with_predicate_codec, \ |
15 | | - map_add_interceptor_codec, map_execute_on_all_keys_codec, map_execute_on_key_codec, map_execute_on_keys_codec, \ |
16 | | - map_execute_with_predicate_codec, map_add_near_cache_entry_listener_codec, map_entries_with_paging_predicate_codec,\ |
17 | | - map_key_set_with_paging_predicate_codec, map_values_with_paging_predicate_codec |
| 6 | + map_add_entry_listener_to_key_with_predicate_codec, map_add_entry_listener_with_predicate_codec, \ |
| 7 | + map_add_index_codec, map_add_interceptor_codec, map_add_near_cache_entry_listener_codec, \ |
| 8 | + map_clear_codec, map_contains_key_codec, map_contains_value_codec, map_delete_codec, \ |
| 9 | + map_entries_with_paging_predicate_codec, map_entries_with_predicate_codec, map_entry_set_codec, \ |
| 10 | + map_evict_all_codec, map_evict_codec, map_execute_on_all_keys_codec, map_execute_on_key_codec, \ |
| 11 | + map_execute_on_keys_codec, map_execute_with_predicate_codec, map_flush_codec, map_force_unlock_codec, \ |
| 12 | + map_get_all_codec, map_get_codec, map_get_entry_view_codec, map_is_empty_codec, map_is_locked_codec, \ |
| 13 | + map_key_set_codec, map_key_set_with_paging_predicate_codec, map_key_set_with_predicate_codec, \ |
| 14 | + map_load_all_codec, map_load_given_keys_codec, map_lock_codec, map_put_all_codec, map_put_codec, \ |
| 15 | + map_put_if_absent_codec, map_put_transient_codec, map_remove_codec, map_remove_entry_listener_codec, \ |
| 16 | + map_remove_if_same_codec, map_replace_codec, map_replace_if_same_codec, map_set_codec, \ |
| 17 | + map_set_ttl_codec, map_size_codec, map_try_lock_codec, map_try_put_codec, map_try_remove_codec, \ |
| 18 | + map_unlock_codec, map_values_codec, map_values_with_paging_predicate_codec, map_values_with_predicate_codec |
18 | 19 | from hazelcast.proxy.base import Proxy, EntryEvent, EntryEventType, get_entry_listener_flags, MAX_SIZE |
19 | 20 | from hazelcast.util import check_not_none, thread_id, to_millis, get_sorted_query_result_set, ITERATION_TYPE |
20 | 21 | from hazelcast import six |
@@ -740,6 +741,21 @@ def set(self, key, value, ttl=-1): |
740 | 741 | value_data = self._to_data(value) |
741 | 742 | return self._set_internal(key_data, value_data, ttl) |
742 | 743 |
|
| 744 | + def set_ttl(self, key, ttl): |
| 745 | + """ |
| 746 | + Updates the TTL (time to live) value of the entry specified by the given key with a new TTL value. New TTL |
| 747 | + value is valid starting from the time this operation is invoked, not since the time the entry was created. |
| 748 | + If the entry does not exist or is already expired, this call has no effect. |
| 749 | +
|
| 750 | + :param key: (object), the key of the map entry. |
| 751 | + :param ttl: (int), maximum time for this entry to stay in the map (0 means infinite, |
| 752 | + negative means map config default) |
| 753 | + """ |
| 754 | + check_not_none(key, "key can't be None") |
| 755 | + check_not_none(ttl, "ttl can't be None") |
| 756 | + key_data = self._to_data(key) |
| 757 | + return self._set_ttl_internal(key_data, ttl) |
| 758 | + |
743 | 759 | def size(self): |
744 | 760 | """ |
745 | 761 | Returns the number of entries in this map. |
@@ -882,6 +898,9 @@ def _set_internal(self, key_data, value_data, ttl): |
882 | 898 | return self._encode_invoke_on_key(map_set_codec, key_data, key=key_data, value=value_data, thread_id=thread_id(), |
883 | 899 | ttl=to_millis(ttl)) |
884 | 900 |
|
| 901 | + def _set_ttl_internal(self, key_data, ttl): |
| 902 | + return self._encode_invoke_on_key(map_set_ttl_codec, key_data, key=key_data, ttl=to_millis(ttl)) |
| 903 | + |
885 | 904 | def _try_remove_internal(self, key_data, timeout): |
886 | 905 | return self._encode_invoke_on_key(map_try_remove_codec, key_data, key=key_data, thread_id=thread_id(), |
887 | 906 | timeout=to_millis(timeout)) |
@@ -1028,6 +1047,10 @@ def _set_internal(self, key_data, value_data, ttl): |
1028 | 1047 | self._invalidate_cache(key_data) |
1029 | 1048 | return super(MapFeatNearCache, self)._set_internal(key_data, value_data, ttl) |
1030 | 1049 |
|
| 1050 | + def _set_ttl_internal(self, key_data, ttl): |
| 1051 | + self._invalidate_cache(key_data) |
| 1052 | + return super(MapFeatNearCache, self)._set_ttl_internal(key_data, ttl) |
| 1053 | + |
1031 | 1054 | def _replace_internal(self, key_data, value_data): |
1032 | 1055 | self._invalidate_cache(key_data) |
1033 | 1056 | return super(MapFeatNearCache, self)._replace_internal(key_data, value_data) |
|
0 commit comments