Key-Value Store API Reference
A comprehensive reference guide to the complete key-value store API.
Overview
Here is the list of all methods used in the key-value store API.
Insert(InsertRequest) → InsertResponse |
Update(UpdateRequest) → UpdateResponse |
Upsert(UpsertRequest) → UpsertResponse |
Fetch(FetchRequest) → FetchResponse |
Delete(DeleteRequest) → DeleteResponse |
List(ListRequest) → ListResponse |
Generate Stubs
memo exposes a gRPC API, offering a portable and language-agnostic channel of interaction. gRPC relies on Protocol Buffers (protobuf) to serialize the remote procedure calls' (RPC) messages. The protocol format and the list of RPCs is described in a simple .proto
file.
As a client, you need to download memo's official memo_kvs.proto
file for interacting with the key-value store API. You then have to generate the package/module/header/class (depending on the language or your choice) that will provide you with functions to easily call the RPCs.
NOTE: In C++, you will need to build the gRPC plugin for protoc
. A clear procedure is given by the gRPC website.
$ go get -u github.com/golang/protobuf/protoc-gen-go
$ export KVS_PROTO_OUT=$GOPATH/src/google.golang.org/grpc/memo/kvs
$ mkdir -p $KVS_PROTO_OUT
$ protoc --proto_path=$HOME/Downloads --go_out=plugins=grpc:$KVS_PROTO_OUT $HOME/Downloads/memo_kvs.proto
$ ls $KVS_PROTO_OUT
memo_kvs.pb.go
$ export KVS_PROTO_OUT=$HOME/projects/memo/src
$ mkdir -p $KVS_PROTO_OUT
$ protoc --proto_path=$HOME/Downloads --cpp_out=$KVS_PROTO_OUT --plugin=protoc-gen-grpc=$(whereis grpc_cpp_plugin) --grpc_out=$KVS_PROTO_OUT $HOME/Downloads/memo_kvs.proto
$ ls -lx $KVS_PROTO_OUT
memo_kvs.grpc.pb.cc memo_kvs.grpc.pb.h memo_kvs.pb.cc memo_kvs.pb.h
$ python3 -m pip install grpcio grpcio-tools
$ export KVS_PROTO_OUT=$HOME/projects/memo/src
$ mkdir -p $KVS_PROTO_OUT
$ python3 -m grpc_tools.protoc --proto_path=$HOME/Downloads --python_out=$KVS_PROTO_OUT --grpc_python_out=$KVS_PROTO_OUT $HOME/Downloads/memo_kvs.proto
$ ls -lx $KVS_PROTO_OUT
memo_kvs_pb2_grpc.py memo_kvs_pb2.py
Deploy memo
To deploy a memo key-value store exposing a gRPC interface, please follow our "getting started with memo" guide.
Methods
Insert(InsertRequest) → InsertResponse
|
Insert a value for the given key.
If the key is already present, the operation will fail.
|
def insert(key, value):
store.Insert(kvs.InsertRequest(key = key, value = value.encode('utf-8')))
func insert(store kvs.KeyValueStoreClient, key string, value string) error {
_, err := store.Insert(context.Background(), &kvs.InsertRequest{Key: key, Value: []byte(value)})
return err
}
void
insert(std::string const& key, std::string const& value)
{
InsertResponse res;
{
grpc::ClientContext ctx;
InsertRequest req;
req.set_key(key);
req.set_value(value);
auto status = store->Insert(&ctx, req, &res);
if (!status.ok())
throw std::runtime_error(status.error_message());
}
}
|
Arguments
InsertRequest
{
string
key,
bytes
value }
|
string |
key |
bytes |
value |
|
Return
|
Exceptions
|
ALREADY_EXISTS : The key already exists.
|
INVALID_ARGUMENT : The key or value format is invalid.
|
|
Update(UpdateRequest) → UpdateResponse
|
Update the value for the given key.
If the key is not already present, the operation will fail.
|
def update(key, value):
store.Update(kvs.UpdateRequest(key = key, value = value.encode('utf-8')))
func update(store kvs.KeyValueStoreClient, key string, value string) error {
_, err := store.Update(context.Background(), &kvs.UpdateRequest{Key: key, Value: []byte(value)})
return err
}
void
update(std::string const& key, std::string const& value)
{
UpdateResponse res;
{
grpc::ClientContext ctx;
UpdateRequest req;
req.set_key(key);
req.set_value(value);
auto status = store->Update(&ctx, req, &res);
if (!status.ok())
throw std::runtime_error(status.error_message());
}
}
|
Arguments
UpdateRequest
{
string
key,
bytes
value }
|
string |
key |
bytes |
value |
|
Return
|
Exceptions
|
NOT_FOUND : The key doesn't exist.
|
INVALID_ARGUMENT : The key or value format is invalid.
|
|
Upsert(UpsertRequest) → UpsertResponse
|
Update (or insert if not present) a value for the given key.
|
def upsert(key, value):
store.Upsert(kvs.UpsertRequest(key = key, value = value.encode('utf-8')))
func upsert(store kvs.KeyValueStoreClient, key string, value string) error {
_, err := store.Upsert(context.Background(), &kvs.UpsertRequest{Key: key, Value: []byte(value)})
return err
}
void
upsert(std::string const& key, std::string const& value)
{
UpsertResponse res;
{
grpc::ClientContext ctx;
UpsertRequest req;
req.set_key(key);
req.set_value(value);
auto status = store->Upsert(&ctx, req, &res);
if (!status.ok())
throw std::runtime_error(status.error_message());
}
}
|
Arguments
UpsertRequest
{
string
key,
bytes
value }
|
string |
key |
bytes |
value |
|
Return
|
Exceptions
|
INVALID_ARGUMENT : The key or value format is invalid.
|
|
Fetch(FetchRequest) → FetchResponse
|
Retrieve the value for the given key.
If the key doesn't exist, the operation will fail.
|
def fetch(key):
return store.Fetch(kvs.FetchRequest(key = key)).value.decode('utf-8')
func fetch(store kvs.KeyValueStoreClient, key string) (string, error) {
res, err := store.Fetch(context.Background(), &kvs.FetchRequest{Key: key})
if err != nil {
return "", err
}
return string(res.Value), nil
}
std::string
fetch(std::string const& key)
{
FetchResponse res;
{
grpc::ClientContext ctx;
FetchRequest req;
req.set_key(key);
auto status = store->Fetch(&ctx, req, &res);
check_status(status);
}
return res.value();
}
|
Arguments
FetchRequest
{
string
key }
|
string |
key |
|
Return
FetchResponse
{
bytes
value }
|
|
Exceptions
|
NOT_FOUND : The key doesn't exist.
|
INVALID_ARGUMENT : The key format is invalid.
|
|
Delete(DeleteRequest) → DeleteResponse
|
Delete the value for the given key.
If the key doesn't exist, the operation will fail.
|
def delete(key):
store.Delete(kvs.DeleteRequest(key = key))
func delete_(store kvs.KeyValueStoreClient, key string) error {
_, err := store.Delete(context.Background(), &kvs.DeleteRequest{Key: key})
return err
}
void
delete_(std::string const& key)
{
DeleteResponse res;
{
grpc::ClientContext ctx;
DeleteRequest req;
req.set_key(key);
auto status = store->Delete(&ctx, req, &res);
if (!status.ok())
throw std::runtime_error(status.error_message());
}
}
|
Arguments
DeleteRequest
{
string
key }
|
string |
key |
|
Return
|
Exceptions
|
NOT_FOUND : The key doesn't exist.
|
INVALID_ARGUMENT : The key format is invalid.
|
|
List(ListRequest) → ListResponse
|
Return the list of keys.
|
def list_():
return list(map(lambda i: i.key, store.List(kvs.ListRequest()).items))
func list(store kvs.KeyValueStoreClient) ([]string, error) {
res, err := store.List(context.Background(), &kvs.ListRequest{})
if err != nil {
return nil, err
}
result := []string{}
for _, i := range res.Items {
result = append(result, i.Key)
}
return result, nil
}
std::vector
list()
{
ListResponse res;
{
grpc::ClientContext ctx;
ListRequest req;
auto status = store->List(&ctx, req, &res);
}
std::vector list;
for (int i = 0; i < res.items_size(); i++)
list.push_back(res.items(i).key());
return list;
}
|
Arguments
ListRequest
{
string
prefix,
string
marker,
string
delimiter,
uint64
maxKeys }
|
string |
prefix |
string |
marker |
string |
delimiter |
uint64 |
maxKeys |
|
Return
ListResponse
{
ListItem
items,
string
prefixes,
bool
truncated }
|
repeated ListItem |
items |
repeated string |
prefixes |
bool |
truncated |
|
Exceptions
|
INVALID_ARGUMENT : One of the paramaters format is not valid.
|
|
Messages
InsertRequest
|
index |
name |
type |
abstract |
1 |
key |
string |
The key |
2 |
value |
bytes |
The value |
InsertResponse
|
index |
name |
type |
abstract |
UpdateRequest
|
index |
name |
type |
abstract |
1 |
key |
string |
The key |
2 |
value |
bytes |
The new value |
UpdateResponse
|
index |
name |
type |
abstract |
UpsertRequest
|
index |
name |
type |
abstract |
1 |
key |
string |
The key |
2 |
value |
bytes |
The new value |
UpsertResponse
|
index |
name |
type |
abstract |
FetchRequest
|
index |
name |
type |
abstract |
1 |
key |
string |
The key of the value to fetch |
FetchResponse
|
index |
name |
type |
abstract |
1 |
value |
bytes |
The value |
DeleteRequest
|
index |
name |
type |
abstract |
1 |
key |
string |
The key of the value to delete |
DeleteResponse
|
index |
name |
type |
abstract |
ListRequest
|
index |
name |
type |
abstract |
1 |
prefix |
string |
Limits the response to keys that begin with the specified prefix |
2 |
marker |
string |
Specifies the key to start with when listing keys |
3 |
delimiter |
string |
A delimiter is a character you use to group keys |
4 |
maxKeys |
uint64 |
The maximum number of entries |
ListItem
|
index |
name |
type |
abstract |
1 |
key |
string |
A key |
ListResponse
|
index |
name |
type |
abstract |
1 |
items |
repeated ListItem |
The list of keys |
2 |
prefixes |
repeated string |
List of prefix for the given delimiter |
3 |
truncated |
bool |
If the list is truncated |
Talk to us on the Internet!
Ask questions to our team or our contributors, get involved in the project...