forked from e-oz/Memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IMemoryStorage.php
108 lines (94 loc) · 2.86 KB
/
IMemoryStorage.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Jamm\Memory;
interface IMemoryStorage
{
/**
* Add value to memory storage, only if this key does not exists (or false will be returned).
*
* @param string $k
* @param mixed $v
* @param int $ttl
* @param array|string $tags
* @return boolean
*/
public function add($k, $v, $ttl = 259200, $tags = NULL);
/**
* Save variable in memory storage
*
* @param string $k - key
* @param mixed $v - value
* @param int $ttl - time to live (store) in seconds
* @param array|string $tags - array of tags for this key
* @return bool
*/
public function save($k, $v, $ttl = 259200, $tags = NULL);
/**
* Read data from memory storage
*
* @param string|array $k (string or array of string keys)
* @param mixed $ttl_left = (ttl - time()) of key. Use to exclude dog-pile effect, with lock/unlock_key methods.
* @return mixed
*/
public function read($k, &$ttl_left = -1);
/**
* Delete key or array of keys from storage
* @param string|array $k - keys
* @return boolean|array - if array of keys was passed, on error will be returned array of not deleted keys, or 'true' on success.
*/
public function del($k);
/**
* Delete old (by ttl) variables from storage
* @return boolean
*/
public function del_old();
/**
* Delete keys by tags
*
* @param array|string $tag - tag or array of tags
* @return boolean
*/
public function del_by_tags($tag);
/**
* Select from storage via callback function
* Only values of 'array' type will be selected
* @param callback $fx ($value_array,$key)
* @param bool $get_array
* @return mixed
*/
public function select_fx($fx, $get_array = false);
/**
* Increment value of key
* @param string $key
* @param mixed $by_value
* if stored value is array:
* if $by_value is value in array, new element will be pushed to the end of array,
* if $by_value is key=>value array, key=>value pair will be added (or updated)
* @param int $limit_keys_count - maximum count of elements (used only if stored value is array)
* @return int|string|array new value of key
*/
public function increment($key, $by_value = 1, $limit_keys_count = 0);
/**
* Get exclusive mutex for key. Key will be still accessible to read and write, but
* another process can exclude dog-pile effect, if before updating the key he will try to get this mutex.
* @param mixed $key
* @param mixed $auto_unlocker_variable - pass empty, just declared variable
*/
public function lock_key($key, &$auto_unlocker_variable);
/**
* Unlock key, locked by method 'lock_key'
* @param KeyAutoUnlocker $auto_unlocker
* @return bool
*/
public function unlock_key(KeyAutoUnlocker $auto_unlocker);
/** Return array of all stored keys */
public function get_keys();
/**
* @return string
*/
public function getLastErr();
/**
* @return array
*/
public function get_stat();
public function getErrLog();
}