The daemon_memcached
plugin supports multiple
get operations (fetching multiple key-value pairs in a single
memcached query) and range queries.
Multiple get Operations
The ability to fetch multiple key-value pairs in a single
memcached query improves read performance by
reducing communication traffic between the client and server. For
InnoDB
, it means fewer transactions and
open-table operations.
The following example demonstrates multiple-get support. The
example uses the test.city
table described in
Creating a New Table and Column Mapping.
Press CTRL+C to copymysql> USE test; mysql> SELECT * FROM test.city; +---------+-----------+-------------+---------+-------+------+--------+ | city_id | name | state | country | flags | cas | expiry | +---------+-----------+-------------+---------+-------+------+--------+ | B | BANGALORE | BANGALORE | IN | 0 | 1 | 0 | | C | CHENNAI | TAMIL NADU | IN | 0 | 0 | 0 | | D | DELHI | DELHI | IN | 0 | 0 | 0 | | H | HYDERABAD | TELANGANA | IN | 0 | 0 | 0 | | M | MUMBAI | MAHARASHTRA | IN | 0 | 0 | 0 | +---------+-----------+-------------+---------+-------+------+--------+
Run a get
command to retrieve all values from
the city
table. The results are returned in a
key-value pair sequence.
Press CTRL+C to copytelnet 127.0.0.1 11211 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. get B C D H M VALUE B 0 22 BANGALORE|BANGALORE|IN VALUE C 0 21 CHENNAI|TAMIL NADU|IN VALUE D 0 14 DELHI|DELHI|IN VALUE H 0 22 HYDERABAD|TELANGANA|IN VALUE M 0 21 MUMBAI|MAHARASHTRA|IN END
When retrieving multiple values in a single get
command, you can switch tables (using
@@
notation) to retrieve the value for the first key, but you cannot
switch tables for subsequent keys. For example, the table switch
in this example is valid:
containers.name
Press CTRL+C to copyget @@aaa.AA BB VALUE @@aaa.AA 8 12 HELLO, HELLO VALUE BB 10 16 GOODBYE, GOODBYE END
Attempting to switch tables again in the same
get
command to retrieve a key value from a
different table is not supported.
There is no limit the number of keys that can be retrieved by a multiple get operation, but there is a 128MB memory limit for storing the result.
Range Queries
For range queries, the daemon_memcached
plugin
supports the following comparison operators:
<
, >
,
<=
, >=
. An operator
must be preceded by an @
symbol. When a range
query finds multiple matching key-value pairs, results are
returned in a key-value pair sequence.
The following examples demonstrate range query support. The
examples use the test.city
table described in
Creating a New Table and Column Mapping.
Press CTRL+C to copymysql> SELECT * FROM test.city; +---------+-----------+-------------+---------+-------+------+--------+ | city_id | name | state | country | flags | cas | expiry | +---------+-----------+-------------+---------+-------+------+--------+ | B | BANGALORE | BANGALORE | IN | 0 | 1 | 0 | | C | CHENNAI | TAMIL NADU | IN | 0 | 0 | 0 | | D | DELHI | DELHI | IN | 0 | 0 | 0 | | H | HYDERABAD | TELANGANA | IN | 0 | 0 | 0 | | M | MUMBAI | MAHARASHTRA | IN | 0 | 0 | 0 | +---------+-----------+-------------+---------+-------+------+--------+
Open a telnet session:
Press CTRL+C to copytelnet 127.0.0.1 11211 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'.
To get all values greater than B
, enter
get @>B
:
Press CTRL+C to copyget @>B VALUE C 0 21 CHENNAI|TAMIL NADU|IN VALUE D 0 14 DELHI|DELHI|IN VALUE H 0 22 HYDERABAD|TELANGANA|IN VALUE M 0 21 MUMBAI|MAHARASHTRA|IN END
To get all values less than M
, enter
get @<M
:
Press CTRL+C to copyget @<M VALUE B 0 22 BANGALORE|BANGALORE|IN VALUE C 0 21 CHENNAI|TAMIL NADU|IN VALUE D 0 14 DELHI|DELHI|IN VALUE H 0 22 HYDERABAD|TELANGANA|IN END
To get all values less than and including M
,
enter get @<=M
:
Press CTRL+C to copyget @<=M VALUE B 0 22 BANGALORE|BANGALORE|IN VALUE C 0 21 CHENNAI|TAMIL NADU|IN VALUE D 0 14 DELHI|DELHI|IN VALUE H 0 22 HYDERABAD|TELANGANA|IN VALUE M 0 21 MUMBAI|MAHARASHTRA|IN
To get values greater than B
but less than
M
, enter get @>B@<M
:
Press CTRL+C to copyget @>B@<M VALUE C 0 21 CHENNAI|TAMIL NADU|IN VALUE D 0 14 DELHI|DELHI|IN VALUE H 0 22 HYDERABAD|TELANGANA|IN END
A maximum of two comparison operators can be parsed, one being
either a 'less than' (@<
) or 'less than or
equal to' (@<=
) operator, and the other
being either a 'greater than' (@>
) or
'greater than or equal to' (@>=
) operator.
Any additional operators are assumed to be part of the key. For
example, if you issue a get
command with three
operators, the third operator (@>C
) is
treated as part of the key, and the get
command
searches for values smaller than M
and greater
than B@>C
.
Press CTRL+C to copyget @<M@>B@>C VALUE C 0 21 CHENNAI|TAMIL NADU|IN VALUE D 0 14 DELHI|DELHI|IN VALUE H 0 22 HYDERABAD|TELANGANA|IN