Skip to content

Commit

Permalink
Lots of changes, not broken up. Shame on me.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmchale committed Mar 7, 2010
1 parent 4533d42 commit 35e1835
Show file tree
Hide file tree
Showing 37 changed files with 691 additions and 25 deletions.
29 changes: 21 additions & 8 deletions public/javascripts/terminal.js
Expand Up @@ -21,6 +21,8 @@ $(document).ready(function () {
append(JSON.stringify(data.response), "response"); append(JSON.stringify(data.response), "response");
} else if (data.error !== undefined) { } else if (data.error !== undefined) {
append(data.error, "error"); append(data.error, "error");
} else if (data.notification !== undefined) {
append(data.notification, "notification", "", true);
} else { } else {
append("Invalid response from TRY-REDIS server.", "error"); append("Invalid response from TRY-REDIS server.", "error");
} }
Expand Down Expand Up @@ -49,16 +51,26 @@ $(document).ready(function () {
} }
}); });


function append(str, klass, prefix) { $("#toolbar").slideDown(500, function () {
$("#input").focus();
});

function append(str, klass, prefix, isHtml) {
if (prefix === undefined) { if (prefix === undefined) {
prefix = ""; prefix = "";
} }


if (!isHtml) {
prefix = escapeHtml(prefix);
str = escapeHtml(str);
}

var message = var message =
'<p class="line">' + '<div class="line ' + klass + '">' +
'<span class="prompt">' + escapeHtml(prefix) + '</span>' + '<div class="nopad">' +
'<span class="' + klass + '">' + escapeHtml(str) + '</span>' + '<span class="prompt">' + prefix + '</span>' +
'</p>' str +
'</div></div>';


$("#log").append(message); $("#log").append(message);
}; };
Expand All @@ -68,9 +80,10 @@ $(document).ready(function () {
}; };


function escapeHtml(str) { function escapeHtml(str) {
str = str.replace(/&/, "&amp;"); str = str.replace(/&/g, "&amp;");
str = str.replace(/</, "&lt;"); str = str.replace(/</g, "&lt;");
str = str.replace(/>/, "&gt;"); str = str.replace(/>/g, "&gt;");
str = str.replace(/\n/g, "<br>");


return str; return str;
}; };
Expand Down
16 changes: 16 additions & 0 deletions redis-doc/decr.markdown
@@ -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.
16 changes: 16 additions & 0 deletions redis-doc/decrby.markdown
@@ -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.
13 changes: 13 additions & 0 deletions redis-doc/del.markdown
@@ -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.
14 changes: 14 additions & 0 deletions redis-doc/exists.markdown
@@ -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.
12 changes: 12 additions & 0 deletions redis-doc/get.markdown
@@ -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
20 changes: 20 additions & 0 deletions redis-doc/getset.markdown
@@ -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.

19 changes: 19 additions & 0 deletions redis-doc/incr.markdown
@@ -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.
16 changes: 16 additions & 0 deletions redis-doc/incrby.markdown
@@ -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.
25 changes: 25 additions & 0 deletions redis-doc/keys.markdown
@@ -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).

18 changes: 18 additions & 0 deletions redis-doc/lindex.markdown
@@ -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.
11 changes: 11 additions & 0 deletions redis-doc/llen.markdown
@@ -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.
15 changes: 15 additions & 0 deletions redis-doc/lpop.markdown
@@ -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.
12 changes: 12 additions & 0 deletions redis-doc/lpush.markdown
@@ -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
22 changes: 22 additions & 0 deletions redis-doc/lrange.markdown
@@ -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.
18 changes: 18 additions & 0 deletions redis-doc/lrem.markdown
@@ -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.
16 changes: 16 additions & 0 deletions redis-doc/lset.markdown
@@ -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.
33 changes: 33 additions & 0 deletions redis-doc/ltrim.markdown
@@ -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 &lt;someelement&gt; 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.
12 changes: 12 additions & 0 deletions redis-doc/mget.markdown
@@ -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

0 comments on commit 35e1835

Please sign in to comment.