Several implementations of servers speaking the memcached protocol have backends that allow for inexpensive operations over ranges of keys. The purpose of this document is to standardize the protocol for making use of these operations.
General Properties of Range Commands
Commands that take ranges all follow the same pattern of key representation. Each range representation will have a minimum and maximum range as well as flags to indicate whether each end is inclusive or exclusive. Either end may be null indicating there's no limit on the side where the null appears. Keys should be treated as byte arrays for range comparisons. The implementation is not expected to perform any type of character conversion or collation.
Abstract Representation of Ranges
null :: means that left/right border is end/begin respectively;
[/] :: means that left/right border respectively is included;
(/) :: means that left/right border respectively is not included;
Binary Protocol Generalities
Request
In the binary protocol, we've got some extra space and can apply that to defining ranges. The "key" field will be used as the start key. A key length of zero represents null as an empty key can't be stored. The extra info will contain the following info:
Flags is a bitmask indicating whether the ends are inclusive or exclusive.
(flags & 1) :: If non-zero, start key is inclusive.
(flags & 2) :: If non-zero, end key is inclusive.
Max results represents the number of objects the operation is permitted to affect. A value of zero indicates there should be no limit.
A server may enforce a maximum limit and respond with an error if the requested limit exceeds the limit enforced by the server (or is zero).
The end key immediately follows the maximum results.
Response
Each requests will generally have many responses and will return similarly to the way stats works in the binary protocol. The final response will be one with an empty key.
The binary protocol allows for commands to operate in a "quiet mode" where most responses are quelled. No such facility is available for the text protocol as it can't be done consistently without introducing new verbs (and then can't be done safely).
Text Protocol Generalities
The general form of a range command is as follows (please see details for how this varies by command):
The end key is optional. If not specified, it is considered null. Null is not explicitly included for the start key as there is a natural minimum of keys which can be used in its place.
The inclusion flags are either 0 or 1. If 0, the endpoint is not included. If 1, the endpoint is included.
This is different from the rget as specified in memcachedb to allow for infinite ranges.
Supported commands
get
Ranged get operations allow multiple key/value pairs returned for a single key request.
set
Ranged set operations allow for a range of existing items to be set to a specific value.
For example, if you have stats stored in a server with keys prefixed as stats. you can reset all of them in a single operation by setting (stats., stats/) to "0". This range specifies everything that begins with "stats." excluding "stats." itself.
Upon batch mutation, each modified value will receive a new distinct CAS identifier.
Binary Protocol Details
Each modified value will respond as a plain set does although the key will be included in the response. The final response will contain no key.
In the case of a quiet request, no response will be given unless the command fails.
Text Protocol Details
The command for text set is rset and has the following form:
Ranged delete will remove all values in the specified range.
For both protocols, the response will be in the form of their respective protocol-specific response in ranged set.
incr
Ranged incr will increment all existing keys within a range by the same amount. This follows the same patterns as existing increment with the obvious exception that it will not initialize keys since it's only modifing things that already exist.
Binary Protocol Details
The extra data includes the standard incr/decr extra data after the ranged extra data.
The responses will include a key and value for every modified item.
Text Protocol Details
The text command for range increment is rincr and is in the following form:
The following table is a quick reference to all of the commands defined herein. Commands omitted from the text column are intentional as they are not defined outside of the binary protocol.
Isolation levels are specifically left unspecified. Operations concurrently working on the same data set may interleave, mutually exclude each other, or just stomp all over each other.
Implementors are encouraged to document their intentions.
Overview
Several implementations of servers speaking the memcached protocol have backends that allow for inexpensive operations over ranges of keys. The purpose of this document is to standardize the protocol for making use of these operations.
General Properties of Range Commands
Commands that take ranges all follow the same pattern of key representation. Each range representation will have a minimum and maximum range as well as flags to indicate whether each end is inclusive or exclusive. Either end may be null indicating there's no limit on the side where the null appears. Keys should be treated as byte arrays for range comparisons. The implementation is not expected to perform any type of character conversion or collation.
Abstract Representation of Ranges
null
:: means that left/right border is end/begin respectively;[
/]
:: means that left/right border respectively is included;(
/)
:: means that left/right border respectively is not included;Binary Protocol Generalities
Request
In the binary protocol, we've got some extra space and can apply that to defining ranges. The "key" field will be used as the start key. A key length of zero represents null as an empty key can't be stored. The extra info will contain the following info:
Flags is a bitmask indicating whether the ends are inclusive or exclusive.
(flags & 1)
:: If non-zero, start key is inclusive.(flags & 2)
:: If non-zero, end key is inclusive.Max results represents the number of objects the operation is permitted to affect. A value of zero indicates there should be no limit.
A server may enforce a maximum limit and respond with an error if the requested limit exceeds the limit enforced by the server (or is zero).
The end key immediately follows the maximum results.
Response
Each requests will generally have many responses and will return similarly to the way stats works in the binary protocol. The final response will be one with an empty key. The binary protocol allows for commands to operate in a "quiet mode" where most responses are quelled. No such facility is available for the text protocol as it can't be done consistently without introducing new verbs (and then can't be done safely).
Text Protocol Generalities
The general form of a range command is as follows (please see details for how this varies by command):
The end key is optional. If not specified, it is considered null. Null is not explicitly included for the start key as there is a natural minimum of keys which can be used in its place.
The inclusion flags are either 0 or 1. If 0, the endpoint is not included. If 1, the endpoint is included.
This is different from the rget as specified in memcachedb to allow for infinite ranges.
Supported commands
get
Ranged get operations allow multiple key/value pairs returned for a single key request.
set
Ranged set operations allow for a range of existing items to be set to a specific value.
For example, if you have stats stored in a server with keys prefixed as
stats.
you can reset all of them in a single operation by setting (stats.
,stats/
) to "0". This range specifies everything that begins with "stats." excluding "stats." itself.Upon batch mutation, each modified value will receive a new distinct CAS identifier.
Binary Protocol Details
Each modified value will respond as a plain set does although the key will be included in the response. The final response will contain no key.
In the case of a quiet request, no response will be given unless the command fails.
Text Protocol Details
The command for text set is rset and has the following form:
The response will be similar to a gets, but with no values included. Example:
append
Ranged append will append a value to every item within a range.
For both protocols, the response will be in the form of their respective protocol-specific response in ranged set.
Text Protocol Details
The command for text append has the following structure:
prepend
Prepend follows the same pattern of append.
delete
Ranged delete will remove all values in the specified range.
For both protocols, the response will be in the form of their respective protocol-specific response in ranged set.
incr
Ranged incr will increment all existing keys within a range by the same amount. This follows the same patterns as existing increment with the obvious exception that it will not initialize keys since it's only modifing things that already exist.
Binary Protocol Details
The extra data includes the standard incr/decr extra data after the ranged extra data.
The responses will include a key and value for every modified item.
Text Protocol Details
The text command for range increment is
rincr
and is in the following form:Responses are the same as a multi-gets.
decr
Ranged decr follows ranged incr.
Command Reference
The following table is a quick reference to all of the commands defined herein. Commands omitted from the text column are intentional as they are not defined outside of the binary protocol.
Isolation
Isolation levels are specifically left unspecified. Operations concurrently working on the same data set may interleave, mutually exclude each other, or just stomp all over each other.
Implementors are encouraged to document their intentions.
P.S.
Original: https://code.google.com/p/memcached/wiki/RangeOps Motive to duplicate - google source code (with project wikis) is closing.
Plan