|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Aerospike; |
| 4 | + |
| 5 | +//////////////////////////////////////////////////////////////////////////////// |
| 6 | +// |
| 7 | +// Creating Client, persisting in permanent storage, retriving from there |
| 8 | +// |
| 9 | +//////////////////////////////////////////////////////////////////////////////// |
| 10 | + |
| 11 | +$socket = "/tmp/asld_grpc.sock"; |
| 12 | + |
| 13 | +$client = Client::connect($socket); |
| 14 | + |
| 15 | +//////////////////////////////////////////////////////////////////////////////// |
| 16 | +// |
| 17 | +// Key object |
| 18 | +// |
| 19 | +//////////////////////////////////////////////////////////////////////////////// |
| 20 | + |
| 21 | +$key = new Key("test", "test", 1); |
| 22 | + |
| 23 | +//////////////////////////////////////////////////////////////////////////////// |
| 24 | +// |
| 25 | +// client->truncate |
| 26 | +// |
| 27 | +//////////////////////////////////////////////////////////////////////////////// |
| 28 | + |
| 29 | +// $ip = new InfoPolicy(); |
| 30 | +// $client->truncate($ip, "test", "test"); |
| 31 | + |
| 32 | +//////////////////////////////////////////////////////////////////////////////// |
| 33 | +// |
| 34 | +// client->put |
| 35 | +// |
| 36 | +//////////////////////////////////////////////////////////////////////////////// |
| 37 | + |
| 38 | +echo "============= PUT ===============\n"; |
| 39 | + |
| 40 | +$wp = new WritePolicy(); |
| 41 | +$wp->setExpiration(Expiration::Seconds(10)); |
| 42 | + |
| 43 | +$bin1 = new Bin("bin1", 111); |
| 44 | + |
| 45 | +for ($x = 0; $x < 10; $x++) { |
| 46 | + $key = new Key("test", "test", $x); |
| 47 | + $bin1 = new Bin("bin1", $x); |
| 48 | + echo "/"; |
| 49 | + $client->put($wp, $key, [$bin1]); |
| 50 | +} |
| 51 | +echo "\n"; |
| 52 | + |
| 53 | +//////////////////////////////////////////////////////////////////////////////// |
| 54 | +// |
| 55 | +// client->get |
| 56 | +// |
| 57 | +//////////////////////////////////////////////////////////////////////////////// |
| 58 | + |
| 59 | +echo "============= GET ===============\n"; |
| 60 | + |
| 61 | +$rp = new ReadPolicy(); |
| 62 | + |
| 63 | +$rp->setMaxRetries(3); |
| 64 | +$timeInMillis = 3000; |
| 65 | +$rp->timeout = $timeInMillis; |
| 66 | + |
| 67 | +var_dump($rp); |
| 68 | + |
| 69 | +for ($x = 0; $x <= 10; $x++) { |
| 70 | + sleep(1); |
| 71 | + $record = $client->get($rp, $key, ["bin1"]); |
| 72 | + if ($record) { |
| 73 | + echo "RECORD " . $x . " TTL = " . ($record->getTtl()) . "\n"; |
| 74 | + echo "RECORD " . $x . " EXP = " . ($record->getExpiration()->inSeconds()) . "\n"; |
| 75 | + } |
| 76 | + else { |
| 77 | + echo "Record " . $x . " expired.\n"; |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +$record = $client->get($rp, $key); |
| 82 | +var_dump($record->bins); |
| 83 | +var_dump($record->generation); |
| 84 | +var_dump($record->key); |
| 85 | + |
| 86 | +//////////////////////////////////////////////////////////////////////////////// |
| 87 | +// |
| 88 | +// $client->delete |
| 89 | +// |
| 90 | +//////////////////////////////////////////////////////////////////////////////// |
| 91 | + |
| 92 | +$deleted = $client->delete($wp, $key); |
| 93 | +var_dump($deleted); |
| 94 | + |
| 95 | +$exists = $client->exists($rp, $key); |
| 96 | +var_dump($exists); |
| 97 | + |
0 commit comments