@@ -31,7 +31,7 @@ docker run -d -p 1408:1408 ghcr.io/oracle/coherence-ce:22.06.3
31
31
## Installation
32
32
33
33
``` bash
34
- pip install coherence
34
+ python3 -m pip install coherence
35
35
```
36
36
37
37
## Documentation
@@ -46,35 +46,43 @@ issues `put()`, `get()`, `size()` and `remove` operations.
46
46
47
47
``` python
48
48
from coherence import NamedCache, Session
49
+ import asyncio
49
50
50
- # create a new Session to the Coherence server
51
- session: Session = Session(None )
52
51
53
- # create a new NamedCache with key of string|int and value of string|int
54
- cache: NamedCache[str , str | int ] = await session.get_cache(" test" )
52
+ async def run_test ():
55
53
56
- # put a new key/value
57
- k: str = " one"
58
- v: str = " only-one"
59
- await cache.put(k, v)
54
+ # create a new Session to the Coherence server
55
+ session: Session = Session(None )
60
56
61
- # get the value for a key in the cache
62
- r = await cache.get(k )
57
+ # create a new NamedCache with key of string|int and value of string|int
58
+ cache: NamedCache[ str , str | int ] = await session.get_cache( " test " )
63
59
64
- # print the value got for a key in the cache
65
- print (" The value of key \" one\" is " + r)
60
+ # put a new key/value
61
+ k: str = " one"
62
+ v: str = " only-one"
63
+ await cache.put(k, v)
66
64
67
- k1: str = " two"
68
- v1: int = 2
69
- await cache.put(k1, v1)
70
- r = await cache.get(k1)
71
- print (" The value of key \" two\" is " + r)
65
+ # get the value for a key in the cache
66
+ r = await cache.get(k)
72
67
73
- # print the size of the cache
74
- print (" Size of the cache test is " + str ( await cache.size()) )
68
+ # print the value got for a key in the cache
69
+ print (" The value of key \" one \" is " + r )
75
70
76
- # remove an entry from the cache
77
- await cache.remove(k1)
71
+ k1: str = " two"
72
+ v1: int = 2
73
+ await cache.put(k1, v1)
74
+ r = await cache.get(k1)
75
+ print (" The value of key \" two\" is " + str (r))
76
+
77
+ # print the size of the cache
78
+ print (" Size of the cache test is " + str (await cache.size()))
79
+
80
+ # remove an entry from the cache
81
+ await cache.remove(k1)
82
+
83
+
84
+ # run the test
85
+ asyncio.run(run_test())
78
86
```
79
87
## Help
80
88
0 commit comments