KV.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Consul;
  12. class KV extends Client implements KVInterface
  13. {
  14. public function get($key, array $options = []): ConsulResponse
  15. {
  16. $params = [
  17. 'query' => $this->resolveOptions($options, ['dc', 'recurse', 'keys', 'separator', 'raw', 'stale', 'consistent', 'default']),
  18. ];
  19. return $this->request('GET', '/v1/kv/' . $key, $params);
  20. }
  21. public function put($key, $value, array $options = []): ConsulResponse
  22. {
  23. $params = [
  24. 'body' => json_encode($value),
  25. 'query' => $this->resolveOptions($options, ['dc', 'flags', 'cas', 'acquire', 'release']),
  26. ];
  27. return $this->request('PUT', '/v1/kv/' . $key, $params);
  28. }
  29. public function delete($key, array $options = []): ConsulResponse
  30. {
  31. $params = [
  32. 'query' => $this->resolveOptions($options, ['dc', 'recurse']),
  33. ];
  34. return $this->request('DELETE', '/v1/kv/' . $key, $params);
  35. }
  36. }