メインコンテンツまでスキップ

Momento StorageのAPIリファレンス

Control APIs

これらのAPIメソッドは、ストアの管理と制御に使用されます。

ストアの作成

指定された名前のストアを作成します。

属性:

NameTypeDescription
storeNameString作成されるストアの名前。

$create_store_response = $storage_client->createStore($store_name);
if ($create_store_response->asSuccess()) {
print("Store $store_name created\n");
} elseif ($create_store_response->asAlreadyExists()) {
print("Store $store_name already exists\n");
} elseif ($err = $create_store_response->asError()) {
print("An error occurred while attempting to create $store_name: {$err->errorCode()} - {$err->message()}\n");
}
備考
Full example code and imports can be found here

ストアの削除

ストアを削除します。

属性:

NameTypeDescription
storeNameString削除するストアの名前。

$delete_store_response = $storage_client->deleteStore($store_name);
if ($err = $delete_store_response->asError()) {
print("An error occurred while attempting to delete $store_name: {$err->errorCode()} - {$err->message()}\n");
} else {
print("Store $store_name deleted\n");
}
備考
Full example code and imports can be found here

ストアのリスト

全てのストアをリストします


$list_stores_response = $storage_client->listStores();
if ($listSuccess = $list_stores_response->asSuccess()) {
print("Found stores:\n");
foreach ($listSuccess->stores() as $store) {
$store_name = $store->name();
print("- $store_name\n");
}
} elseif ($err = $list_stores_response->asError()) {
print("An error occurred while attempting to list stores: {$err->errorCode()} - {$err->message()}\n");
}
備考
Full example code and imports can be found here

Data APIs

これらのAPIメソッドは、ストア内のデータを直接操作するために使用されます。

Put

値をストアに入れる。このキーの値がすでに存在する場合は、新しい値に置き換えられます。

NameTypeDescription
storeNameStringストアの名前
keyString値を追加するキー
valueString / Bytes / Integer / Double保存する値

$put_response = $storage_client->putString($store_name, "test-key", "test-value");
if ($put_response->asSuccess()) {
print("Key 'test-key' stored successfully\n");
} elseif ($err = $put_response->asError()) {
print("An error occurred while attempting to store 'test-key': {$err->errorCode()} - {$err->message()}\n");
}

// Momento storage also supports int, float, and bytes types.
// Because strings in PHP are a series of bytes, the putBytes method accepts a string as the value.
$put_response = $storage_client->putBytes($store_name, "test-key", "test-value");
$put_response = $storage_client->putInt($store_name, "test-key", 42);
$put_response = $storage_client->putFloat($store_name, "test-key", 3.14);
備考
Full example code and imports can be found here

Get

与えられたキーに対して格納されている値を取得します。

NameTypeDescription
storeNameStringストアの名前
keyString値を取得するキー

$get_response = $storage_client->get($store_name, "test-key");
if ($found = $get_response->asFound()) {
$value_type = $found->type();
if ($value_type == StorageValueType::STRING) {
print("Got string value: " . $found->valueString() . "\n");
} elseif ($value_type == StorageValueType::INT) {
print("Got integer value: " . $found->valueInt() . "\n");
} elseif ($value_type == StorageValueType::FLOAT) {
print("Got float value: " . $found->valueFloat() . "\n");
} elseif ($value_type == StorageValueType::BYTES) {
// This case is not expected in this example as PHP doesn't have a native byte type
print("Got bytes value: " . $found->valueBytes() . "\n");
}
// You may also pull the value directly from the response without type checking
print("Retrieved value for key 'test-key': {$get_response->value()}\n");
} elseif ($get_response->asNotFound()) {
print("Key 'test-key' was not found in store $store_name\n");
} elseif ($err = $get_response->asError()) {
print("An error occurred while attempting to get key 'test-key' from store $store_name: {$err->errorCode()} - {$err->message()}\n");
}
備考
Full example code and imports can be found here

Delete

指定されたキーに格納されている値を削除します。

NameTypeDescription
storeNameStringストアの名前
keyString値を削除するキー

$delete_response = $storage_client->delete($store_name, "test-key");
if ($delete_response->asSuccess()) {
print("Key 'test-key' deleted successfully\n");
} elseif ($err = $delete_response->asError()) {
print("An error occurred while attempting to delete key 'test-key' from store $store_name: {$err->errorCode()} - {$err->message()}\n");
}
備考
Full example code and imports can be found here

SDKにおけるAPIサポートの現状

様々なSDK言語におけるAPIサポートの現状については、言語サポートページを参照してください。

Momento SDKにおけるストレージAPIサポートの現状

Storage

A matrix of SDK support for Momento Storage APIs

FeatureNode.jsWeb.NETPythonGoJavaKotlinElixirPHPRustRubySwiftDart
createStore
deleteStore
listStores
put
get
delete