The Basics
NamedMap and NamedCache are dict-like structures allowing users to store data within a remote Coherence cluster.
The following is an example of using a NamedMap to store, get, and remove simple keys and values:
1# Copyright (c) 2023, Oracle and/or its affiliates.
2# Licensed under the Universal Permissive License v 1.0 as shown at
3# https://oss.oracle.com/licenses/upl.
4
5import asyncio
6
7from coherence import NamedMap, Session
8
9
10async def do_run() -> None:
11 """
12 Demonstrates basic CRUD operations against a NamedMap using
13 `int` keys and `str` values.
14
15 :return: None
16 """
17 session: Session = await Session.create()
18 try:
19 named_map: NamedMap[int, str] = await session.get_map("my-map")
20
21 print("Put key 1; value one")
22 await named_map.put(1, "one")
23
24 print("Value for key 1 is :", await named_map.get(1))
25
26 print("NamedMap size is :", await named_map.size())
27
28 print("Updating value of key 1 to ONE from ", await named_map.put(1, "ONE"))
29
30 print("Value for key 1 is :", await named_map.get(1))
31
32 print("Removing key 1, current value :", await named_map.remove(1))
33
34 print("NamedMap size is :", await named_map.size())
35 finally:
36 await session.close()
37
38
39asyncio.run(do_run())