4
4
5
5
namespace Dew \TablestoreDriver ;
6
6
7
- use Dew \Tablestore \Attribute ;
8
- use Dew \Tablestore \Exceptions \TablestoreException ;
9
- use Dew \Tablestore \PlainbufferWriter ;
10
- use Dew \Tablestore \PrimaryKey ;
11
- use Dew \Tablestore \Responses \RowDecodableResponse ;
12
- use Dew \Tablestore \Tablestore ;
7
+ use Dew \Acs \Tablestore \Attribute ;
8
+ use Dew \Acs \Tablestore \InstanceException ;
9
+ use Dew \Acs \Tablestore \Messages \ComparatorType ;
10
+ use Dew \Acs \Tablestore \Messages \Filter ;
11
+ use Dew \Acs \Tablestore \Messages \FilterType ;
12
+ use Dew \Acs \Tablestore \Messages \SingleColumnValueFilter ;
13
+ use Dew \Acs \Tablestore \Plainbuf ;
14
+ use Dew \Acs \Tablestore \PlainBufferWriter ;
15
+ use Dew \Acs \Tablestore \PrimaryKey ;
16
+ use Dew \Acs \Tablestore \TablestoreInstance ;
13
17
use Illuminate \Contracts \Cache \LockProvider ;
14
18
use Illuminate \Contracts \Cache \Store ;
15
19
use Illuminate \Support \Carbon ;
16
20
use Illuminate \Support \InteractsWithTime ;
17
21
use InvalidArgumentException ;
18
- use Protos \ComparatorType ;
19
- use Protos \Filter ;
20
- use Protos \FilterType ;
21
- use Protos \SingleColumnValueFilter ;
22
22
use RuntimeException ;
23
23
24
24
final class TablestoreStore implements LockProvider, Store
@@ -34,7 +34,7 @@ final class TablestoreStore implements LockProvider, Store
34
34
* Create a Tablestore cache store.
35
35
*/
36
36
public function __construct (
37
- protected Tablestore $ tablestore ,
37
+ protected TablestoreInstance $ tablestore ,
38
38
protected string $ table ,
39
39
protected string $ keyAttribute = 'key ' ,
40
40
protected string $ valueAttribute = 'value ' ,
@@ -52,16 +52,19 @@ public function __construct(
52
52
*/
53
53
public function get ($ key )
54
54
{
55
- $ item = $ this ->tablestore ->table ($ this ->table )
55
+ $ buffer = $ this ->tablestore ->table ($ this ->table )
56
56
->whereKey ($ this ->keyAttribute , $ this ->prefix .$ key )
57
57
->where ($ this ->expirationAttribute , '> ' , Carbon::now ()->getTimestamp ())
58
- ->get ()->getDecodedRow ();
58
+ ->get ()
59
+ ->getRow ();
59
60
60
- if ($ item === null ) {
61
+ if ($ buffer === '' ) {
61
62
return ;
62
63
}
63
64
64
- /** @var \Dew\Tablestore\Contracts\HasValue[] */
65
+ $ item = Plainbuf::decode ($ buffer );
66
+
67
+ /** @var \Dew\Acs\Tablestore\Cells\HasValue[] */
65
68
$ values = $ item [$ this ->valueAttribute ] ?? [];
66
69
67
70
return isset ($ values [0 ]) ? $ this ->unserialize ($ values [0 ]->value ()) : null ;
@@ -95,23 +98,25 @@ public function many(array $keys)
95
98
96
99
$ result = array_fill_keys ($ keys , null );
97
100
98
- /** @var \Protos \TableInBatchGetRowResponse[] */
101
+ /** @var \Dew\Acs\Tablestore\Messages \TableInBatchGetRowResponse[] */
99
102
$ tables = $ response ->getTables ();
100
103
101
- /** @var \Protos \RowInBatchGetRowResponse[] */
104
+ /** @var \Dew\Acs\Tablestore\Messages \RowInBatchGetRowResponse[] */
102
105
$ rows = $ tables [0 ]->getRows ();
103
106
104
107
foreach ($ rows as $ row ) {
105
- $ item = ( new RowDecodableResponse ( $ row))-> getDecodedRow ();
108
+ $ buffer = $ row-> getRow ();
106
109
107
- if ($ item === null ) {
110
+ if ($ buffer === '' ) {
108
111
continue ;
109
112
}
110
113
111
- /** @var \Dew\Tablestore\Cells\StringPrimaryKey */
114
+ $ item = Plainbuf::decode ($ buffer );
115
+
116
+ /** @var \Dew\Acs\Tablestore\Cells\StringPrimaryKey */
112
117
$ key = $ item [$ this ->keyAttribute ];
113
118
114
- /** @var \Dew\Tablestore\Contracts \HasValue[] */
119
+ /** @var \Dew\Acs\ Tablestore\Cells \HasValue[] */
115
120
$ values = $ item [$ this ->valueAttribute ] ?? [];
116
121
117
122
if (isset ($ values [0 ])) {
@@ -183,7 +188,7 @@ public function add($key, $value, $seconds)
183
188
{
184
189
try {
185
190
Attribute::integer ($ this ->expirationAttribute , Carbon::now ()->getTimestamp ())
186
- ->toFormattedValue ($ now = new PlainbufferWriter );
191
+ ->toFormattedValue ($ now = new PlainBufferWriter );
187
192
188
193
// Include only items that do not exist or that have expired
189
194
// expression: expiration <= now
@@ -205,8 +210,8 @@ public function add($key, $value, $seconds)
205
210
Attribute::createFromValue ($ this ->valueAttribute , $ this ->serialize ($ value )),
206
211
Attribute::integer ($ this ->expirationAttribute , $ this ->toTimestamp ($ seconds )),
207
212
]);
208
- } catch (TablestoreException $ e ) {
209
- if ($ e ->getError ()->getCode () === 'OTSConditionCheckFail ' ) {
213
+ } catch (InstanceException $ e ) {
214
+ if ($ e ->getError ()? ->getCode() === 'OTSConditionCheckFail ' ) {
210
215
return false ;
211
216
}
212
217
@@ -235,8 +240,8 @@ public function increment($key, $value = 1)
235
240
]);
236
241
237
242
return true ;
238
- } catch (TablestoreException $ e ) {
239
- if ($ e ->getError ()->getCode () === 'OTSConditionCheckFail ' ) {
243
+ } catch (InstanceException $ e ) {
244
+ if ($ e ->getError ()? ->getCode() === 'OTSConditionCheckFail ' ) {
240
245
return false ;
241
246
}
242
247
@@ -263,8 +268,8 @@ public function decrement($key, $value = 1)
263
268
]);
264
269
265
270
return true ;
266
- } catch (TablestoreException $ e ) {
267
- if ($ e ->getError ()->getCode () === 'OTSConditionCheckFail ' ) {
271
+ } catch (InstanceException $ e ) {
272
+ if ($ e ->getError ()? ->getCode() === 'OTSConditionCheckFail ' ) {
268
273
return false ;
269
274
}
270
275
@@ -399,7 +404,7 @@ private function toTimestamp(int $seconds): int
399
404
/**
400
405
* The underlying Tablestore client.
401
406
*/
402
- public function getClient (): Tablestore
407
+ public function getClient (): TablestoreInstance
403
408
{
404
409
return $ this ->tablestore ;
405
410
}
0 commit comments