Exemplo n.º 1
0
def run():
  if len(sys.argv) == 1:
    print(_USAGE)

    sys.exit(0)

  cmd = sys.argv[1]

  channel = implementations.insecure_channel('127.0.0.1', _GRPC_PORT)
  client_stub = kv_pb2.beta_create_KV_stub(channel)

  if cmd == "get":
    # ensure a key was provided
    if len(sys.argv) != 3:
      print(_USAGE)
      sys.exit(1)

    # get the key to fetch
    key = sys.argv[2]

    # create the request
    get_request = kv_pb2.GetRequest(key=key)

    # send the request to the server
    response = client_stub.Get(get_request, _TIMEOUT_SECONDS)

    print(response.value)
    sys.exit(0)

  elif cmd == "set":
    # ensure a key and value were provided
    if len(sys.argv) < 4:
      print(_USAGE)
      sys.exit(1)

    # get the key and the full text of value
    key = sys.argv[2]
    value = " ".join(sys.argv[3:])

    # create the request
    set_request = kv_pb2.SetRequest(key=key, value=value)

    # send the request to the server
    response = client_stub.Set(set_request, _TIMEOUT_SECONDS)

    print("set %s to %s" % (key, value))
Exemplo n.º 2
0
    def set(self, key, value):
        r = kv.SetRequest(key=key, value=value)
        data = r.SerializeToString()
        data = pack('!cI', b'\0', len(data)) + data

        return requests.post(HOST + "/kv.KV/Set", data=data, headers=HEADERS)
Exemplo n.º 3
0
 def set(self, key, value):
     req = kv_pb2.SetRequest(key=key, value=value)
     return self._stub.set(req)