Skip to content

Commit 711fdec

Browse files
authored
User doc update (#7)
* Added documentation for Session * Updated documentation for Session * Added documentation for installation and basic operations * Fix validation error
1 parent 2e7db7e commit 711fdec

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

docs/basics.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,60 @@
55
66
The Basics
77
==========
8+
9+
he map (`NamedMap`) and cache (`NamedCache`) implementations provide the same basic features as the Map provided
10+
by Python except for the following differences:
11+
12+
* key equality isn't restricted to reference equality
13+
* insertion order is not maintained
14+
* `set()` calls cannot be chained because of the asynchronous nature of the API
15+
16+
.. note::
17+
The only difference between `NamedCache` and `NamedMap` is that the `NamedCache` allows associating a `time-to-live` on the cache entry, while `NamedMap` does not
18+
19+
For the following examples, let's assume that we have a Map defined in Coherence named `Test`.
20+
To get access to the map from the client:
21+
22+
.. code-block:: python
23+
24+
from coherence import NamedMap, Session
25+
import asyncio
26+
27+
# create a new Session to the Coherence server
28+
session: Session = Session(None)
29+
# create or get a map named Test from the session
30+
map: NamedMap = session.get_map("Test")
31+
32+
Once we have a handle to our map, we can invoke the same basic operations in Python:
33+
34+
.. code-block:: python
35+
36+
await map.size()
37+
# returns 0
38+
39+
await map.put("key1", "value1")
40+
await map.put("key2", "value2")
41+
42+
await map.size()
43+
# returns 2
44+
45+
await map.get("key1")
46+
# returns "value1"
47+
48+
await map.get("key2")
49+
# returns "value2"
50+
51+
await map.contains_key("key2")
52+
# returns true
53+
54+
await map.contains_key("key3")
55+
# returns false
56+
57+
await map.keys()
58+
# ["key1", "key2"]
59+
60+
await map.values()
61+
# ["value1", "value2"]
62+
63+
await map.entries()
64+
# [{key: "key1", value: "value1"}, {key: "key2", value: "value2"}]

docs/installation.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55
66
Installation
77
============
8+
9+
To install the Coherence Python Client one would need to do a pip install of the coherence package as shown below:
10+
11+
.. code-block:: bash
12+
13+
python3 -m pip install coherence

docs/sessions.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,61 @@
55
66
Sessions
77
========
8+
9+
Coherence uses the concept of a `Session` to manage a set of related Coherence resources,
10+
such as maps and/or caches. When using the Coherence Python Client, a `Session` connects to a specific
11+
gRPC endpoint and uses a specific serialization format to marshal requests and responses.
12+
This means that different sessions using different serializers may connect to the same server endpoint. Typically,
13+
for efficiency the client and server would be configured to use matching serialization formats to avoid
14+
deserialization of data on the server, but this does not have to be the case. If the server is using a different
15+
serializer for the server-side caches, it must be able to deserialize the client's requests, so there must be
16+
a serializer configured on the server to match that used by the client.
17+
18+
.. note::
19+
Currently, the Coherence Python client only supports JSON serialization
20+
21+
A `Session` is constructed using an `Options` instance, or a generic object with the same keys and values.
22+
23+
The currently supported arguments foe `Options` are:
24+
- `address` - the address of the Coherence gRPC proxy. This defaults to `localhost:1408`.
25+
- `request_timeout_seconds` - the gRPC request timeout in seconds. This defaults to `30.0`.
26+
- `channel_options` - per-request gRPC channel options.
27+
- `tls_options` - options related to the configuration of TLS.
28+
29+
- `enabled` - determines if TLS is enabled or not. This defaults to `false` (NOTE: assumes `true` if all three `COHERENCE_TLS_*` (see subsequent bullets) environment variables are defined)
30+
- `ca_cert_path` - the path to the CA certificate. This may be configured using the environment variable `COHERENCE_TLS_CERTS_PATH`
31+
- `client_cert_path` - the path to the client certificate. This may be configured with the environment variable `COHERENCE_TLS_CLIENT_CERT`
32+
- `client_key_path` - the path to the client certificate key. This may be configured with the environment variable `COHERENCE_TLS_CLIENT_KEY`
33+
34+
.. code-block:: python
35+
36+
from coherence import NamedCache, Session
37+
import asyncio
38+
39+
# create a new Session to the Coherence server
40+
session: Session = Session(None)
41+
42+
This is the simplest invocation which assumes the following defaults:
43+
- `address` is `localhost:1408`
44+
- `request_timeout_seconds` is `30.0`
45+
- `tls_options` is `disabled`
46+
47+
To use values other than the default, create a new `Options` instance, configure as desired,
48+
and pass it to the constructor of the `Session`:
49+
50+
.. code-block:: python
51+
52+
from coherence import NamedCache, Session
53+
import asyncio
54+
55+
# create a new Session to the Coherence server
56+
addr: str = 'example.com:4444'
57+
opt: Options = Options(addr, default_scope, default_request_timeout, default_format)
58+
session: Session = Session(opt)
59+
60+
It's also possible to control the default address the session will bind to by providing
61+
an address via the `COHERENCE_SERVER_ADDRESS` environment variable. The format of the value would
62+
be the same as if you configured it programmatically as the above example shows. The default timeout
63+
can also be configured using `COHERENCE_CLIENT_REQUEST_TIMEOUT` environment variable.
64+
65+
Once the session has been constructed, it will now be possible to create maps and caches.

0 commit comments

Comments
 (0)