Compare Exchange in Cluster-Wide Session
-
Compare-Exchange items can be created and managed on the advanced session (
session.advanced
)
Other options are listed in this compare-exchange overview. -
When working with compare-exchange items from the session,
the session must be opened as a cluster-wide session. -
In this page:
Create compare-exchange
Example
# The session must be first opened with cluster-wide mode
session.advanced.cluster_transaction.create_compare_exchange_value(
key="Best NoSQL Transactional Database",
item="RavenDB",
)
session.save_changes()
save_changes()
throws aConcurrencyException
if the key already exists.- A
RuntimeError
exception is thrown if the session was Not opened as cluster-wide.
Syntax
session.advanced.cluster_transaction.create_compare_exchange_value(key, value)
Parameters | Type | Description |
---|---|---|
key | str |
The key for the compare-exchange item to be created This string can be up to 512 bytes |
value | T |
The value to associate with this key |
Return Value | Description |
---|---|
CompareExchangeValue[T] |
The new compare-exchange item is returned |
The CompareExchangeValue
Parameters | Type | Description |
---|---|---|
key | str |
The compare-exchange item key This string can be up to 512 bytes |
value | T |
The value associated with the key |
index | int |
Index for concurrency control |
Get compare-exchange
Get single value
session.advanced.cluster_transaction.get_compare_exchange_value(key)
Parameters | Type | Description |
---|---|---|
key | str |
The key for a compare-exchange item whose value is requested |
Return Value | Description |
---|---|
CompareExchangeValue[T] |
The requested value If the key doesn't exist the value associated with it will be None |
Get multiple values
session.advanced.cluster_transaction.get_compare_exchange_values(keys)
Parameters | Type | Description |
---|---|---|
keys | List[str] |
An array of compare-exchange keys whose values are requested |
Return Value | Description |
---|---|
Dict[str, CompareExchangeValue[T]] |
A dictionary of requested values If a key doesn't exist the value associated with it will be None |
Get compare-exchange lazily
# Single value
session.advanced.cluster_transaction.lazily.get_compare_exchange_value(key)
# Multiple values
session.advanced.cluster_transaction.lazily.get_compare_exchange_values(keys)
Parameters | Type | Description |
---|---|---|
key | str |
The key for a compare-exchange item whose value is requested |
keys | List[str] |
An array of compare-exchange keys whose values are requested |
Return Value | Description |
---|---|
Lazy[CompareExchangeValue[T]] |
The requested value If the key doesn't exist the value associated with it will be None |
Lazy[Dict[str, CompareExchangeValue[T]]] |
A dictionary of requested values If a key doesn't exist the value associated with it will be None |
Delete compare-exchange
To delete a compare exchange item, use either of the following methods.
# Delete by key & index
session.advanced.cluster_transaction.delete_compare_exchange_value(key, index)
# Delete by compare-exchange item
session.advanced.cluster_transaction.delete_compare_exchange_value(item)
Parameters | Type | Description |
---|---|---|
key | str |
The key for the compare-exchange item to delete |
index | int |
The index for the compare-exchange item to delete |
item | CompareExchangeValue[T] |
The compare-exchange item to delete |