-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lots of changes, not broken up. Shame on me.
- Loading branch information
Alex McHale
committed
Mar 7, 2010
1 parent
4533d42
commit 35e1835
Showing
37 changed files
with
691 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# DECR key integer | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) | ||
|
||
**DESCRIPTION**: Increment or decrement the number stored at key by one. If the | ||
key does not exist or contains a value of a wrong type, set the key to the | ||
value of "0" before to perform the increment or decrement operation. | ||
|
||
INCRBY and DECRBY work just like INCR and DECR but instead to | ||
increment/decrement by 1 the increment/decrement is integer. | ||
|
||
INCR commands are limited to 64 bit signed integers. | ||
|
||
**RETURN VALUE**: Integer reply, this commands will reply with the new value | ||
of key after the increment or decrement. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# DECRBY key integer | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) | ||
|
||
**DESCRIPTION**: Increment or decrement the number stored at key by one. If the | ||
key does not exist or contains a value of a wrong type, set the key to the | ||
value of "0" before to perform the increment or decrement operation. | ||
|
||
INCRBY and DECRBY work just like INCR and DECR but instead to | ||
increment/decrement by 1 the increment/decrement is integer. | ||
|
||
INCR commands are limited to 64 bit signed integers. | ||
|
||
**RETURN VALUE**: Integer reply, this commands will reply with the new value | ||
of key after the increment or decrement. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# DEL key1 key2 ... keyN # | ||
|
||
**TIME COMPLEXITY:** | ||
O(1) | ||
|
||
**DESCRIPTION:** | ||
Remove the specified keys. If a given key does not exist no operation is | ||
performed for this key. The commnad returns the number of keys removed. | ||
|
||
**RETURN VALUE:** | ||
|
||
* An integer greater than 0 if one or more keys were removed. | ||
* 0 if none of the specified key existed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# EXISTS key # | ||
|
||
**TIME COMPLEXITY:** | ||
O(1) | ||
|
||
**DESCRIPTION:** | ||
Test if the specified key exists. The command returns "0" if the key exists, | ||
otherwise "1" is returned. Note that even keys set with an empty string as | ||
value will return "1". | ||
|
||
**RETURN VALUE:** | ||
|
||
* 1 if the key exists. | ||
* 0 if the key does not exist. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# GET key # | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) | ||
|
||
**DESCRIPTION**: | ||
Get the value of the specified key. If the key does not exist the special | ||
value 'nil' is returned. If the value stored at key is not a string an error | ||
is returned because GET can only handle string values. | ||
|
||
**RETURN VALUE**: | ||
Bulk reply |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# GETSET key value # | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) | ||
|
||
**DESCRIPTION**: | ||
GETSET is an atomic set this value and return the old value command. Set key | ||
to the string value and return the old value stored at key. The string can't | ||
be longer than 1073741824 bytes (1 GB). | ||
|
||
**RETURN VALUE**: | ||
Bulk reply | ||
|
||
**DESIGN PATTERNS**: | ||
GETSET can be used together with INCR for counting with atomic reset when a | ||
given condition arises. For example a process may call INCR against the key | ||
mycounter every time some event occurred, but from time to time we need to get | ||
the value of the counter and reset it to zero atomically using GETSET | ||
mycounter 0. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# INCR key | ||
# INCRBY key integer | ||
# DECR key integer | ||
# DECRBY key integer | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) | ||
|
||
**DESCRIPTION**: Increment or decrement the number stored at key by one. If the | ||
key does not exist or contains a value of a wrong type, set the key to the | ||
value of "0" before to perform the increment or decrement operation. | ||
|
||
INCRBY and DECRBY work just like INCR and DECR but instead to | ||
increment/decrement by 1 the increment/decrement is integer. | ||
|
||
INCR commands are limited to 64 bit signed integers. | ||
|
||
**RETURN VALUE**: Integer reply, this commands will reply with the new value | ||
of key after the increment or decrement. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# INCRBY key integer | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) | ||
|
||
**DESCRIPTION**: Increment or decrement the number stored at key by one. If the | ||
key does not exist or contains a value of a wrong type, set the key to the | ||
value of "0" before to perform the increment or decrement operation. | ||
|
||
INCRBY and DECRBY work just like INCR and DECR but instead to | ||
increment/decrement by 1 the increment/decrement is integer. | ||
|
||
INCR commands are limited to 64 bit signed integers. | ||
|
||
**RETURN VALUE**: Integer reply, this commands will reply with the new value | ||
of key after the increment or decrement. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# KEYS pattern # | ||
|
||
**TIME COMPLEXITY:** | ||
O(n) (with n being the number of keys in the DB, and assuming keys and | ||
pattern of limited length) | ||
|
||
**DESCRIPTION:** | ||
Returns all the keys matching the glob-style pattern as space separated | ||
strings. For example if you have in the database the keys "foo" and "foobar" | ||
the command "KEYS foo*" will return "foo foobar". | ||
|
||
Glob style patterns examples: | ||
|
||
* h?llo will match hello hallo hhllo | ||
* h*llo will match hllo heeeello | ||
* h[ae]llo will match hello and hallo, but not hillo | ||
|
||
Use \ to escape special chars if you want to match them verbatim. | ||
|
||
**RETURN VALUE:** | ||
Bulk reply, specifically a string in the form of space separated list of keys. | ||
Note that most client libraries will return an Array of keys and not a single | ||
string with space separated keys (that is, split by " " is performed in the | ||
client library usually). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# LINDEX *key* *index* | ||
|
||
**TIME COMPLEXITY**: | ||
O(n) (with n being the length of the list) | ||
|
||
**DESCRIPTION**: | ||
Return the specified element of the list stored at the specified key. 0 is the | ||
first element, 1 the second and so on. Negative indexes are supported, for | ||
example -1 is the last element, -2 the penultimate and so on. | ||
|
||
If the value stored at key is not of list type an error is returned. If the | ||
index is out of range an empty string is returned. | ||
|
||
Note that even if the average time complexity is O(n) asking for the first or | ||
the last element of the list is O(1). | ||
|
||
**RETURN VALUE**: | ||
Bulk reply containing the requested element. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# LLEN *key* | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) | ||
|
||
**DESCRIPTION**: | ||
Return the length of the list stored at the specified key. If the key does not | ||
exist zero is returned (the same behaviour as for empty lists). If the value | ||
stored at *key* is not a list an error is returned. | ||
|
||
**RETURN VALUE**: Integer reply of the length of the list. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# LPOP *key* | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) | ||
|
||
**DESCRIPTION**: | ||
Atomically return and remove the first (LPOP) or last (RPOP) element of the | ||
list. For example if the list contains the elements "a","b","c" LPOP will | ||
return "a" and the list will become "b","c". | ||
|
||
If the *key* does not exist or the list is already empty the special value | ||
'nil' is returned. | ||
|
||
**RETURN VALUE**: | ||
Bulk reply. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# LPUSH *key* *string* | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) | ||
|
||
**DESCRIPTION**: | ||
Add the *string* value to the head (RPUSH) or tail (LPUSH) of the list stored | ||
at *key*. If the key does not exist an empty list is created just before the | ||
append operation. If the key exists but is not a List an error is returned. | ||
|
||
**RETURN VALUE**: | ||
Status code reply |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# LRANGE *key* *start* *end* | ||
|
||
**TIME COMPLEXITY**: | ||
O(n) (with n being the length of the range) | ||
|
||
**DESCRIPTION**: | ||
Return the specified elements of the list stored at the specified key. Start | ||
and end are zero-based indexes. 0 is the first element of the list (the list | ||
head), 1 the next element and so on. | ||
|
||
For example LRANGE foobar 0 2 will return the first three elements of the list. | ||
|
||
*start* and *end* can also be negative numbers indicating offsets from the end | ||
of the list. For example -1 is the last element of the list, -2 the penultimate | ||
element and so on. | ||
|
||
Indexes out of range will not produce an error: if start is over the end of the | ||
list, or start <tt>></tt> end, an empty list is returned. If end is over the end | ||
of the list Redis will threat it just like the last element of the list. | ||
|
||
**RETURN VALUE**: | ||
A multi bulk reply of a list of elements in the specified range. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# LREM <i>key</i> <i>count</i> <i>value</i> | ||
|
||
**TIME COMPLEXITY**: | ||
O(N) (with N being the length of the list) | ||
|
||
**DESCRIPTION**: | ||
Remove the first *count* occurrences of the *value* element from the list. If | ||
*count* is zero all the elements are removed. If *count* is negative elements | ||
are removed from tail to head, instead to go from head to tail that is the | ||
normal behaviour. So for example LREM with count -2 and *hello* as value to | ||
remove against the list (a,b,c,hello,x,hello,hello) will lave the list | ||
(a,b,c,hello,x). The number of removed elements is returned as an integer, see | ||
below for more information about the returned value. Note that non existing | ||
keys are considered like empty lists by LREM, so LREM against non existing | ||
keys will always return 0. | ||
|
||
**RETURN VALUE**: | ||
An integer reply containing the number of removed elements if the operation succeeded. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# LSET *key* *index* *value* | ||
|
||
**TIME COMPLEXITY**: | ||
O(N) (with N being the length of the list) | ||
|
||
**DESCRIPTION**: | ||
Set the list element at *index* (see LINDEX for information about the *index* | ||
argument) with the new *value*. Out of range indexes will generate an error. | ||
Note that setting the first or last elements of the list is O(1). | ||
|
||
Similarly to other list commands accepting indexes, the index can be negative | ||
to access elements starting from the end of the list. So -1 is the last element, | ||
-2 is the penultimate, and so forth. | ||
|
||
**RETURN VALUE**: | ||
Status code reply. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# LTRIM *key* *start* *end* | ||
|
||
**TIME COMPLEXITY**: | ||
O(n) (with n being len of list - len of range) | ||
|
||
**DESCRIPTION**: | ||
Trim an existing list so that it will contain only the specified range of | ||
elements specified. Start and end are zero-based indexes. 0 is the first | ||
element of the list (the list head), 1 the next element and so on. | ||
|
||
For example LTRIM foobar 0 2 will modify the list stored at foobar key so | ||
that only the first three elements of the list will remain. | ||
|
||
*start* and *end* can also be negative numbers indicating offsets from the | ||
end of the list. For example -1 is the last element of the list, -2 the | ||
penultimate element and so on. | ||
|
||
Indexes out of range will not produce an error: if start is over the end of | ||
the list, or start > end, an empty list is left as value. If end over the | ||
end of the list Redis will threat it just like the last element of the list. | ||
|
||
Hint: the obvious use of LTRIM is together with LPUSH/RPUSH. For example: | ||
|
||
LPUSH mylist <someelement> LTRIM mylist 0 99 | ||
|
||
The above two commands will push elements in the list taking care that the | ||
list will not grow without limits. This is very useful when using Redis to | ||
store logs for example. It is important to note that when used in this way | ||
LTRIM is an O(1) operation because in the average case just one element is | ||
removed from the tail of the list. | ||
|
||
**RETURN VALUE**: | ||
Status code reply. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# MGET key1 key2 ... keyN # | ||
|
||
**TIME COMPLEXITY**: | ||
O(1) for every key | ||
|
||
**DESCRIPTION**: | ||
Get the values of all the specified keys. If one or more keys dont exist or is | ||
not of type String, a 'nil' value is returned instead of the value of the | ||
specified key, but the operation never fails. | ||
|
||
**RETURN VALUE**: | ||
Multi bulk reply |
Oops, something went wrong.