interface KeyValueStoreInterface (View source)

Defines the interface for key/value store implementations.

Methods

string
getCollectionName()

Returns the name of this collection.

bool
has(string $key)

Returns whether a given key exists in the store.

mixed
get(string $key, mixed $default = NULL)

Returns the stored value for a given key.

array
getMultiple(array $keys)

Returns the stored key/value pairs for a given set of keys.

array
getAll()

Returns all stored key/value pairs in the collection.

set(string $key, mixed $value)

Saves a value for a given key.

bool
setIfNotExists(string $key, mixed $value)

Saves a value for a given key if it does not exist yet.

setMultiple(array $data)

Saves key/value pairs.

rename(string $key, string $new_key)

Renames a key.

delete(string $key)

Deletes an item from the key/value store.

deleteMultiple(array $keys)

Deletes multiple items from the key/value store.

deleteAll()

Deletes all items from the key/value store.

Details

string getCollectionName()

Returns the name of this collection.

Return Value

string

The name of this collection.

bool has(string $key)

Returns whether a given key exists in the store.

Parameters

string $key

The key to check.

Return Value

bool

TRUE if the key exists, FALSE otherwise.

mixed get(string $key, mixed $default = NULL)

Returns the stored value for a given key.

Parameters

string $key

The key of the data to retrieve.

mixed $default

The default value to use if the key is not found.

Return Value

mixed

The stored value, or the default value if no value exists.

array getMultiple(array $keys)

Returns the stored key/value pairs for a given set of keys.

Determine the best return value for non-existing keys in https://www.drupal.org/node/2787737

Parameters

array $keys

A list of keys to retrieve.

Return Value

array

An associative array of items successfully returned, indexed by key.

array getAll()

Returns all stored key/value pairs in the collection.

Return Value

array

An associative array containing all stored items in the collection.

set(string $key, mixed $value)

Saves a value for a given key.

Parameters

string $key

The key of the data to store.

mixed $value

The data to store.

bool setIfNotExists(string $key, mixed $value)

Saves a value for a given key if it does not exist yet.

Parameters

string $key

The key of the data to store.

mixed $value

The data to store.

Return Value

bool

TRUE if the data was set, FALSE if it already existed.

setMultiple(array $data)

Saves key/value pairs.

Parameters

array $data

An associative array of key/value pairs.

rename(string $key, string $new_key)

Renames a key.

Parameters

string $key

The key to rename.

string $new_key

The new key name.

delete(string $key)

Deletes an item from the key/value store.

Parameters

string $key

The item name to delete.

deleteMultiple(array $keys)

Deletes multiple items from the key/value store.

Parameters

array $keys

A list of item names to delete.

deleteAll()

Deletes all items from the key/value store.