Repository navigation
Expand file tree
/
Copy pathStorageInterface.php
More file actions
49 lines (44 loc) · 2.17 KB
/
Copy pathStorageInterface.php
File metadata and controls
49 lines (44 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Aternos\Lock\Storage;
use Exception;
/**
* Interface for a storage that can be used to perform etcd-like operations.
*/
interface StorageInterface
{
/**
* Put `$value` if `$key` value matches `$previousValue` and return true. If the new value does not match and
* `$returnNewValueOnFail` is true return the new value, otherwise return false.
* @param string $key
* @param string $value The new value to set
* @param string|null $previousValue The previous value to compare against. If null is provided, the comparison
* should check that the key does not exist yet.
* @param bool $returnNewValueOnFail if true the new value of the key should be returned if the operation fails
* @return bool|string|null true if the operation succeeded, false if it failed and `$returnNewValueOnFail` is
* false, otherwise the new value of the key
* @throws StorageException a known, retryable error occurred
* @throws Exception an unknown error occurred
*/
public function putIf(string $key, string $value, ?string $previousValue, bool $returnNewValueOnFail = false): bool|string|null;
/**
* Delete if $key value matches $previous value otherwise $returnNewValueOnFail
*
* @param string $key
* @param string|null $previousValue The previous value to compare against. If null is provided, the comparison
* should check that the key does not exist yet.
* @param bool $returnNewValueOnFail
* @return bool|string|null true if the operation succeeded, false if it failed and `$returnNewValueOnFail` is
* false, otherwise the new value of the key
* @throws StorageException a known, retryable error occurred
* @throws Exception an unknown error occurred
*/
public function deleteIf(string $key, ?string $previousValue, bool $returnNewValueOnFail = false): bool|string|null;
/**
* Get the value of a key
* @param string $key
* @return string|null the value of the key or null if the key does not exist
* @throws StorageException a known, retryable error occurred
* @throws Exception an unknown error occurred
*/
public function get(string $key): ?string;
}