Stream for better performance of intensive operations.
More...
#include <tkrzw_dbm_remote.h>
|
| ~Stream () |
| Destructor. More...
|
|
| Stream (const Stream &rhs)=delete |
| Copy and assignment are disabled. More...
|
|
Stream & | operator= (const Stream &rhs)=delete |
|
void | Cancel () |
| Cancels the current operation. More...
|
|
Status | Echo (std::string_view message, std::string *echo) |
| Sends a message and gets back the echo message. More...
|
|
Status | Get (std::string_view key, std::string *value=nullptr) |
| Gets the value of a record of a key. More...
|
|
std::string | GetSimple (std::string_view key, std::string_view default_value="") |
| Gets the value of a record of a key, in a simple way. More...
|
|
Status | Set (std::string_view key, std::string_view value, bool overwrite=true, bool ignore_result=false) |
| Sets a record of a key and a value. More...
|
|
Status | Remove (std::string_view key, bool ignore_result=false) |
| Removes a record of a key. More...
|
|
Status | Append (std::string_view key, std::string_view value, std::string_view delim="", bool ignore_result=false) |
| Appends data at the end of a record of a key. More...
|
|
Status | CompareExchange (std::string_view key, std::string_view expected, std::string_view desired, std::string *actual=nullptr, bool *found=nullptr, double retry_wait=0, bool notify=false) |
| Compares the value of a record and exchanges if the condition meets. More...
|
|
Status | Increment (std::string_view key, int64_t increment=1, int64_t *current=nullptr, int64_t initial=0, bool ignore_result=false) |
| Increments the numeric value of a record. More...
|
|
int64_t | IncrementSimple (std::string_view key, int64_t increment=1, int64_t initial=0) |
| Increments the numeric value of a record, in a simple way. More...
|
|
Stream for better performance of intensive operations.
An instance of this class dominates a thread on the server so you should destroy when it is no longer in use.
◆ ~Stream()
tkrzw::RemoteDBM::Stream::~Stream |
( |
| ) |
|
◆ Stream()
tkrzw::RemoteDBM::Stream::Stream |
( |
const Stream & |
rhs | ) |
|
|
explicitdelete |
Copy and assignment are disabled.
◆ Cancel()
void tkrzw::RemoteDBM::Stream::Cancel |
( |
| ) |
|
Cancels the current operation.
This is called by another thread than the thread doing the operation.
◆ Echo()
Status tkrzw::RemoteDBM::Stream::Echo |
( |
std::string_view |
message, |
|
|
std::string * |
echo |
|
) |
| |
Sends a message and gets back the echo message.
- Parameters
-
message | The message to send. |
echo | The pointer to a string object to contain the echo message. |
- Returns
- The result status.
◆ Get()
Status tkrzw::RemoteDBM::Stream::Get |
( |
std::string_view |
key, |
|
|
std::string * |
value = nullptr |
|
) |
| |
Gets the value of a record of a key.
- Parameters
-
key | The key of the record. |
value | The pointer to a string object to contain the result value. If it is nullptr, the value data is ignored. |
- Returns
- The result status. If there's no matching record, NOT_FOUND_ERROR is returned.
◆ GetSimple()
std::string tkrzw::RemoteDBM::Stream::GetSimple |
( |
std::string_view |
key, |
|
|
std::string_view |
default_value = "" |
|
) |
| |
Gets the value of a record of a key, in a simple way.
- Parameters
-
key | The key of the record. |
default_value | The value to be returned on failure. |
- Returns
- The value of the matching record on success, or the default value on failure.
◆ Set()
Status tkrzw::RemoteDBM::Stream::Set |
( |
std::string_view |
key, |
|
|
std::string_view |
value, |
|
|
bool |
overwrite = true , |
|
|
bool |
ignore_result = false |
|
) |
| |
Sets a record of a key and a value.
- Parameters
-
key | The key of the record. |
value | The value of the record. |
overwrite | Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned. |
ignore_result | If true, the result status is not checked. |
- Returns
- The result status. If overwriting is abandoned, DUPLICATION_ERROR is returned.
◆ Remove()
Status tkrzw::RemoteDBM::Stream::Remove |
( |
std::string_view |
key, |
|
|
bool |
ignore_result = false |
|
) |
| |
Removes a record of a key.
- Parameters
-
key | The key of the record. |
ignore_result | If true, the result status is not checked. |
- Returns
- The result status. If there's no matching record, NOT_FOUND_ERROR is returned.
◆ Append()
Status tkrzw::RemoteDBM::Stream::Append |
( |
std::string_view |
key, |
|
|
std::string_view |
value, |
|
|
std::string_view |
delim = "" , |
|
|
bool |
ignore_result = false |
|
) |
| |
Appends data at the end of a record of a key.
- Parameters
-
key | The key of the record. |
value | The value to append. |
delim | The delimiter to put after the existing record. |
ignore_result | If true, the result status is not checked. |
- Returns
- The result status.
If there's no existing record, the value is set without the delimiter.
◆ CompareExchange()
Status tkrzw::RemoteDBM::Stream::CompareExchange |
( |
std::string_view |
key, |
|
|
std::string_view |
expected, |
|
|
std::string_view |
desired, |
|
|
std::string * |
actual = nullptr , |
|
|
bool * |
found = nullptr , |
|
|
double |
retry_wait = 0 , |
|
|
bool |
notify = false |
|
) |
| |
Compares the value of a record and exchanges if the condition meets.
- Parameters
-
key | The key of the record. |
expected | The expected value. If the data is nullptr, no existing record is expected. If it is DBM::ANY_DATA, an existing record with any value is expacted. |
desired | The desired value. If the data is nullptr, the record is to be removed. If it is DBM::ANY_DATA, no update is done. |
actual | The pointer to a string object to contain the actual value of the existing record. If it is nullptr, it is ignored. |
found | The pointer to a variable to contain whether there is an existing record. If it is nullptr, it is ignored. |
retry_wait | The maximum wait time in seconds before retrying. If it is zero, no retry is done. If it is positive, retry is done after waiting for the notifications of the next update for the time at most. |
notify | If true, a notification signal is sent to wake up retrying threads. |
- Returns
- The result status. If the condition doesn't meet, INFEASIBLE_ERROR is returned.
◆ Increment()
Status tkrzw::RemoteDBM::Stream::Increment |
( |
std::string_view |
key, |
|
|
int64_t |
increment = 1 , |
|
|
int64_t * |
current = nullptr , |
|
|
int64_t |
initial = 0 , |
|
|
bool |
ignore_result = false |
|
) |
| |
Increments the numeric value of a record.
- Parameters
-
key | The key of the record. |
increment | The incremental value. If it is INT64MIN, the current value is not changed and a new record is not created. |
current | The pointer to an integer to contain the current value. If it is nullptr, it is ignored. |
initial | The initial value. |
ignore_result | If true, the result status is not checked. |
- Returns
- The result status.
The record value is stored as an 8-byte big-endian integer. Negative is also supported.
◆ IncrementSimple()
int64_t tkrzw::RemoteDBM::Stream::IncrementSimple |
( |
std::string_view |
key, |
|
|
int64_t |
increment = 1 , |
|
|
int64_t |
initial = 0 |
|
) |
| |
Increments the numeric value of a record, in a simple way.
- Parameters
-
key | The key of the record. |
increment | The incremental value. |
initial | The initial value. |
- Returns
- The current value or INT64MIN on failure.
The record value is treated as a decimal integer. Negative is also supported.