Databases Reference
In-Depth Information
4.1.1
What is a key-value store?
A
key-value store
is a simple database that when presented with a simple string (the key)
returns an arbitrary large BLOB of data (the value). Key-value stores have no query
language; they provide a way to add and remove key-value pairs (a combination of key
and value where the key is bound to the value until a new value is assigned) into/from
a database.
A key-value store is like a dictionary. A dictionary has a list of words and each word
has one or more definitions, as shown in figure 4.1.
The dictionary is a simple key-value store where word entries represent keys and
definitions represent values. Inasmuch as dictionary entries are sorted alphabetically
by word, retrieval is quick; it's not necessary to scan the entire dictionary to find what
you're looking for. Like the dictionary, a key-value store is also indexed by the key; the
key points directly to the value, resulting in rapid retrieval, regardless of the number
of items in your store.
One of the benefits of not specifying a data type for the value of a key-value store is
that you can store any data type that you want in the value. The system will store the
information as a
BLOB
and return the same
BLOB
when a
GET
(retrieval) request is
made. It's up to the application to determine what type of data is being used, such as a
string,
XML
file, or binary image.
The key in a key-value store is flexible and can be represented by many formats:
Logical path names to images or files
Artificially generated strings created from a hash of the value
REST
web service calls
SQL
queries
Values, like keys, are also flexible and can be any
BLOB
of data, such as images, web
pages, documents, or videos. See figure 4.2 for an example of a common key-value
store.
Figure 4.1
A sample
dictionary entry showing
how a dictionary is similar
to a key-value store. In this
case, the word you're
looking up (amphora) is
called the
key
and the
definitions are the
values
.