From 43f30ac0f9bcc4a7afb06136a8dfe5b703be7935 Mon Sep 17 00:00:00 2001 From: antirez Date: Sat, 5 Dec 2009 16:58:10 +0100 Subject: [PATCH] HTML doc update --- doc/AuthCommand.html | 2 +- doc/Benchmarks.html | 4 +- doc/BgsaveCommand.html | 8 +- doc/CommandReference.html | 9 +- doc/Comparisons.html | 4 +- doc/ConnectionHandlingSidebar.html | 36 ++++++ doc/ControlCommandsSidebar.html | 36 ++++++ doc/DbsizeCommand.html | 8 +- doc/DelCommand.html | 8 +- doc/ExistsCommand.html | 8 +- doc/ExpireCommand.html | 8 +- doc/FAQ.html | 5 +- doc/Features.html | 4 +- doc/FlushallCommand.html | 8 +- doc/FlushdbCommand.html | 8 +- doc/FromSqlToDataStructures.html | 2 +- doc/GenericCommandsSidebar.html | 36 ++++++ doc/GetCommand.html | 8 +- doc/GetsetCommand.html | 6 +- doc/IncrCommand.html | 9 +- doc/InfoCommand.html | 6 +- doc/IntroductionToRedisDataTypes.html | 151 ++++++++++++++++++++++++++ doc/KeysCommand.html | 8 +- doc/LastsaveCommand.html | 8 +- doc/LindexCommand.html | 8 +- doc/ListCommandsSidebar.html | 36 ++++++ doc/Lists.html | 43 ++++++++ doc/LlenCommand.html | 8 +- doc/LpopCommand.html | 8 +- doc/LrangeCommand.html | 8 +- doc/LremCommand.html | 8 +- doc/LsetCommand.html | 8 +- doc/LtrimCommand.html | 8 +- doc/MgetCommand.html | 8 +- doc/MonitorCommand.html | 8 +- doc/MoveCommand.html | 8 +- doc/MsetCommand.html | 7 +- doc/QuickStart.html | 17 +-- doc/QuitCommand.html | 2 +- doc/README.html | 31 +----- doc/RandomkeyCommand.html | 8 +- doc/RenameCommand.html | 8 +- doc/RenamenxCommand.html | 8 +- doc/RoadMap.html | 6 +- doc/RpoplpushCommand.html | 8 +- doc/RpushCommand.html | 8 +- doc/SaddCommand.html | 8 +- doc/SaveCommand.html | 8 +- doc/ScardCommand.html | 8 +- doc/SdiffCommand.html | 8 +- doc/SdiffstoreCommand.html | 8 +- doc/SelectCommand.html | 8 +- doc/SetCommand.html | 8 +- doc/SetCommandsSidebar.html | 36 ++++++ doc/SetnxCommand.html | 8 +- doc/Sets.html | 37 +++++++ doc/ShutdownCommand.html | 8 +- doc/SinterCommand.html | 10 +- doc/SinterstoreCommand.html | 10 +- doc/SismemberCommand.html | 8 +- doc/SlaveofCommand.html | 8 +- doc/SmembersCommand.html | 8 +- doc/SmoveCommand.html | 8 +- doc/SortCommand.html | 8 +- doc/SortedSetCommandsSidebar.html | 36 ++++++ doc/SortedSets.html | 37 +++++++ doc/SpopCommand.html | 40 +++++++ doc/SrandmemberCommand.html | 40 +++++++ doc/SremCommand.html | 8 +- doc/StringCommandsSidebar.html | 36 ++++++ doc/Strings.html | 37 +++++++ doc/SunionCommand.html | 8 +- doc/SunionstoreCommand.html | 8 +- doc/TemplateCommand.html | 2 +- doc/TtlCommand.html | 8 +- doc/TypeCommand.html | 2 +- doc/ZaddCommand.html | 9 +- doc/ZcardCommand.html | 7 +- doc/ZrangeCommand.html | 8 +- doc/ZrangebyscoreCommand.html | 10 +- doc/ZremCommand.html | 7 +- doc/ZremrangebyscoreCommand.html | 39 +++++++ doc/ZscoreCommand.html | 8 +- doc/index.html | 2 +- 84 files changed, 927 insertions(+), 282 deletions(-) create mode 100644 doc/ConnectionHandlingSidebar.html create mode 100644 doc/ControlCommandsSidebar.html create mode 100644 doc/GenericCommandsSidebar.html create mode 100644 doc/IntroductionToRedisDataTypes.html create mode 100644 doc/ListCommandsSidebar.html create mode 100644 doc/Lists.html create mode 100644 doc/SetCommandsSidebar.html create mode 100644 doc/Sets.html create mode 100644 doc/SortedSetCommandsSidebar.html create mode 100644 doc/SortedSets.html create mode 100644 doc/SpopCommand.html create mode 100644 doc/SrandmemberCommand.html create mode 100644 doc/StringCommandsSidebar.html create mode 100644 doc/Strings.html create mode 100644 doc/ZremrangebyscoreCommand.html diff --git a/doc/AuthCommand.html b/doc/AuthCommand.html index a326a845..ff734a60 100644 --- a/doc/AuthCommand.html +++ b/doc/AuthCommand.html @@ -26,7 +26,7 @@
-

AUTH _password_

Request for authentication in a password protected Redis server.A Redis server can be instructed to require a password before to allow clientsto issue commands. This is done using the requirepass directive in theRedis configuration file.
+ #sidebar ConnectionHandlingSidebar

AUTH _password_

Request for authentication in a password protected Redis server.A Redis server can be instructed to require a password before to allow clientsto issue commands. This is done using the requirepass directive in theRedis configuration file.
If the password given by the client is correct the server replies withan OK status code reply and starts accepting commands from the client.Otherwise an error is returned and the clients needs to try a new password.Note that for the high performance nature of Redis it is possible to trya lot of passwords in parallel in very short time, so make sure to generatea strong and very long password so that this attack is infeasible.

Return value

Status code reply diff --git a/doc/Benchmarks.html b/doc/Benchmarks.html index 53f8bb44..aadc3d93 100644 --- a/doc/Benchmarks.html +++ b/doc/Benchmarks.html @@ -26,8 +26,8 @@
-

How Fast is Redis?

Redis includes the redis-benchmark utility that simulates SETs/GETs done by N clients at the same time sending M total queries (it is similar to the Apache's ab utility). Below you'll find the full output of the benchmark executed against a Linux box.

-Results: about 110000 SETs per second, about 81000 GETs per second.

Latency percentiles

+                    

How Fast is Redis?

Redis includes the redis-benchmark utility that simulates SETs/GETs done by N clients at the same time sending M total queries (it is similar to the Apache's ab utility). Below you'll find the full output of the benchmark executed against a Linux box.

  • The test was done with 50 simultaneous clients performing 100000 requests.
  • The value SET and GET is a 256 bytes string.
  • The Linux box is running Linux 2.6, it's Xeon X3320 2.5Ghz.
  • Text executed using the loopback interface (127.0.0.1).
+Results: about 110000 SETs per second, about 81000 GETs per second.

Latency percentiles

 ./redis-benchmark -n 100000
 
 ====== SET ======
diff --git a/doc/BgsaveCommand.html b/doc/BgsaveCommand.html
index 5fab9485..33468ae5 100644
--- a/doc/BgsaveCommand.html
+++ b/doc/BgsaveCommand.html
@@ -16,7 +16,7 @@
             
-BgsaveCommand: Contents
  BGSAVE
    Return value
    See also +BgsaveCommand: Contents
  BGSAVE
    Return value

BgsaveCommand

@@ -26,10 +26,10 @@
-

BGSAVE

+ #sidebar ControlCommandsSidebar

BGSAVE

Save the DB in background. The OK code is immediately returned.Redis forks, the parent continues to server the clients, the childsaves the DB on disk then exit. A client my be able to check if theoperation succeeded using the LASTSAVE command.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/CommandReference.html b/doc/CommandReference.html index b1074c6e..fb55c45a 100644 --- a/doc/CommandReference.html +++ b/doc/CommandReference.html @@ -16,7 +16,7 @@

CommandReference

@@ -27,12 +27,11 @@
= Redis Command Reference =

Every command name links to a specific wiki page describing the behavior of the command.

Connection handling

  • QUIT close the connection
  • AUTH simple password authentication if enabled
-

Commands operating on string values

  • SET key value set a key to a string value
  • GET key return the string value of the key
  • GETSET key value set a key to a string returning the old value of the key
  • MGET key1 key2 ... keyN multi-get, return the strings values of the keys
  • SETNX key value set a key to a string value if the key does not exist
  • MSET key1 value1 key2 value2 ... keyN valueN set a multiple keys to multiple values in a single atomic operation
  • MSETNX key1 value1 key2 value2 ... keyN valueN set a multiple keys to multiple values in a single atomic operation if none of the keys already exist
  • INCR key increment the integer value of key
  • INCRBY key integer increment the integer value of key by integer
  • DECR key decrement the integer value of key
  • DECRBY key integer decrement the integer value of key by integer
  • EXISTS key test if a key exists
  • DEL key delete a key
  • TYPE key return the type of the value stored at key
-

Commands operating on the key space

  • KEYS pattern return all the keys matching a given pattern
  • RANDOMKEY return a random key from the key space
  • RENAME oldname newname rename the old key in the new one, destroing the newname key if it already exists
  • RENAMENX oldname newname rename the old key in the new one, if the newname key does not already exist
  • DBSIZE return the number of keys in the current db
  • EXPIRE set a time to live in seconds on a key
  • TTL get the time to live in seconds of a key
+

Commands operating on all the kind of values

  • EXISTS key test if a key exists
  • DEL key delete a key
  • TYPE key return the type of the value stored at key
  • KEYS pattern return all the keys matching a given pattern
  • RANDOMKEY return a random key from the key space
  • RENAME oldname newname rename the old key in the new one, destroing the newname key if it already exists
  • RENAMENX oldname newname rename the old key in the new one, if the newname key does not already exist
  • DBSIZE return the number of keys in the current db
  • EXPIRE set a time to live in seconds on a key
  • TTL get the time to live in seconds of a key
  • SELECT index Select the DB having the specified index
  • MOVE key dbindex Move the key from the currently selected DB to the DB having as index dbindex
  • FLUSHDB Remove all the keys of the currently selected DB
  • FLUSHALL Remove all the keys from all the databases
+

Commands operating on string values

  • SET key value set a key to a string value
  • GET key return the string value of the key
  • GETSET key value set a key to a string returning the old value of the key
  • MGET key1 key2 ... keyN multi-get, return the strings values of the keys
  • SETNX key value set a key to a string value if the key does not exist
  • MSET key1 value1 key2 value2 ... keyN valueN set a multiple keys to multiple values in a single atomic operation
  • MSETNX key1 value1 key2 value2 ... keyN valueN set a multiple keys to multiple values in a single atomic operation if none of the keys already exist
  • INCR key increment the integer value of key
  • INCRBY key integer increment the integer value of key by integer
  • DECR key decrement the integer value of key
  • DECRBY key integer decrement the integer value of key by integer

Commands operating on lists

  • RPUSH key value Append an element to the tail of the List value at key
  • LPUSH key value Append an element to the head of the List value at key
  • LLEN key Return the length of the List value at key
  • LRANGE key start end Return a range of elements from the List at key
  • LTRIM key start end Trim the list at key to the specified range of elements
  • LINDEX key index Return the element at index position from the List at key
  • LSET key index value Set a new value as the element at index position of the List at key
  • LREM key count value Remove the first-N, last-N, or all the elements matching value from the List at key
  • LPOP key Return and remove (atomically) the first element of the List at key
  • RPOP key Return and remove (atomically) the last element of the List at key
  • RPOPLPUSH srckey dstkey Return and remove (atomically) the last element of the source List stored at _srckey_ and push the same element to the destination List stored at _dstkey_

Commands operating on sets

  • SADD key member Add the specified member to the Set value at key
  • SREM key member Remove the specified member from the Set value at key
  • SPOP key Remove and return (pop) a random element from the Set value at key
  • SMOVE srckey dstkey member Move the specified member from one Set to another atomically
  • SCARD key Return the number of elements (the cardinality) of the Set at key
  • SISMEMBER key member Test if the specified value is a member of the Set at key
  • SINTER key1 key2 ... keyN Return the intersection between the Sets stored at key1, key2, ..., keyN
  • SINTERSTORE dstkey key1 key2 ... keyN Compute the intersection between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey
  • SUNION key1 key2 ... keyN Return the union between the Sets stored at key1, key2, ..., keyN
  • SUNIONSTORE dstkey key1 key2 ... keyN Compute the union between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey
  • SDIFF key1 key2 ... keyN Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN
  • SDIFFSTORE dstkey key1 key2 ... keyN Compute the difference between the Set key1 and all the Sets key2, ..., keyN, and store the resulting Set at dstkey
  • SMEMBERS key Return all the members of the Set value at key
  • SRANDMEMBER key Return a random member of the Set value at key
-

Commands operating on sorted sets (zsets, Redis version >

1.1) ==

  • ZADD key score member Add the specified member to the Set value at key or update the score if it already exist
  • ZREM key member Remove the specified member from the Set value at key
  • ZRANGE key start end Return a range of elements from the sorted set at key
  • ZREVRANGE key start end Return a range of elements from the sorted set at key, exactly like ZRANGE, but the sorted set is ordered in traversed in reverse order, from the greatest to the smallest score
  • ZRANGEBYSCORE key min max Return all the elements with score >= min and score <= max (a range query) from the sorted set
  • ZCARD key Return the cardinality (number of elements) of the sorted set at key
  • ZSCORE key element Return the score associated with the specified element of the sorted set at key
-

Multiple databases handling commands

  • SELECT index Select the DB having the specified index
  • MOVE key dbindex Move the key from the currently selected DB to the DB having as index dbindex
  • FLUSHDB Remove all the keys of the currently selected DB
  • FLUSHALL Remove all the keys from all the databases
+

Commands operating on sorted sets (zsets, Redis version >

1.1) ==

  • ZADD key score member Add the specified member to the Set value at key or update the score if it already exist
  • ZREM key member Remove the specified member from the Set value at key
  • ZRANGE key start end Return a range of elements from the sorted set at key
  • ZREVRANGE key start end Return a range of elements from the sorted set at key, exactly like ZRANGE, but the sorted set is ordered in traversed in reverse order, from the greatest to the smallest score
  • ZRANGEBYSCORE key min max Return all the elements with score >= min and score <= max (a range query) from the sorted set
  • ZCARD key Return the cardinality (number of elements) of the sorted set at key
  • ZSCORE key element Return the score associated with the specified element of the sorted set at key
  • ZREMRANGEBYSCORE key min max Remove all the elements with score >= min and score <= max from the sorted set

Sorting

  • SORT key BY pattern LIMIT start end GET pattern ASC|DESC ALPHA Sort a Set or a List accordingly to the specified parameters

Persistence control commands

  • SAVE Synchronously save the DB on disk
  • BGSAVE Asynchronously save the DB on disk
  • LASTSAVE Return the UNIX time stamp of the last successfully saving of the dataset on disk
  • SHUTDOWN Synchronously save the DB on disk, then shutdown the server

Remote server control commands

  • INFO Provide information and statistics about the server
  • MONITOR Dump all the received requests in real time
  • SLAVEOF Change the replication settings
diff --git a/doc/Comparisons.html b/doc/Comparisons.html index 25e6699e..14c253a4 100644 --- a/doc/Comparisons.html +++ b/doc/Comparisons.html @@ -26,8 +26,8 @@
- if your are asking yourself how is Redis different fom other key-value stores here you will find it compared to some of the most popular contendors (all great software) in this category.

Memcached

  • Memcached is not persistent, it just holds everything in memory without saving since its main goal is to be used as a cache, while Redis is persistent.
-
  • Like memcached Redis uses a key-value model, but while keys can just be strings, values in Redis can be Lists, Sets or OrderedSets and complex operations like intersections, set/get n-th element of lists, pop/push of elements, can be performed against sets and lists.
+ if your are asking yourself how is Redis different fom other key-value stores here you will find it compared to some of the most popular contendors (all great software) in this category.

Memcached

  • Memcached is not persistent, it just holds everything in memory without saving since its main goal is to be used as a cache, while Redis is persistent.
+
  • Like memcached Redis uses a key-value model, but while keys can just be strings, values in Redis can be Lists, Sets or SortedSets and complex operations like intersections, set/get n-th element of lists, pop/push of elements, can be performed against sets and lists.

Tokyo Cabinet / Toyo Tyrant

Redis and Tokyo Cabinet can be used for the same applications, but actually they are very different beasts. If you read Twitter messages of people involved in scalable things both products are reported to work well, but surely there are times where one or the other can be the best choice.

  • Tokyo Cabinet writes synchronously on disk, Redis takes the whole dataset on memory and writes on disk asynchronously. Tokyo Cabinet is safer and probably a better idea if your dataset is going to be bigger than RAM, but Redis is faster (note that Redis supports master-slave replication that is trivial to setup, so you are safe anyway if you want a setup where data can't be lost even after a disaster).
  • Redis supports higher level operations and data structures. Tokyo Cabinet supports a kind of database that is able to organize data into rows with named fields (in a way very similar to Berkeley DB) but can't do things like server side List and Set operations Redis is able to do: pushing or popping from Lists in an atomic way, in O(1) time complexity, server side Set intersections, Sorting of schema free data in complex ways (By the way TC supports sorting in the table-based database format). Redis on the other hand does not support the abstraction of tables with fields, the idea is that you can build this stuff in software easily if you really need a table-alike approach.
  • Tokyo Cabinet does not implement a networking layer. You have to use a networking layer called Tokyo Tyrant that interfaces to Tokyo Cabinet so you can talk to Tokyo Cabinet in a client-server fashion. In Redis the networking support is built-in inside the server, and is basically the only interface between the external world and the dataset.
diff --git a/doc/ConnectionHandlingSidebar.html b/doc/ConnectionHandlingSidebar.html new file mode 100644 index 00000000..09392041 --- /dev/null +++ b/doc/ConnectionHandlingSidebar.html @@ -0,0 +1,36 @@ + + + + + + + +
+ + + +
+
+ +ConnectionHandlingSidebar: Contents +
+ +

ConnectionHandlingSidebar

+ +
+ +
+ +
+ == Connection handling ==

+
+ +
+
+ + + diff --git a/doc/ControlCommandsSidebar.html b/doc/ControlCommandsSidebar.html new file mode 100644 index 00000000..e081134e --- /dev/null +++ b/doc/ControlCommandsSidebar.html @@ -0,0 +1,36 @@ + + + + + + + +
+ + + +
+
+ +ControlCommandsSidebar: Contents +
+ +

ControlCommandsSidebar

+ +
+ +
+ +
+ == Control Commands ==

+
+ +
+
+ + + diff --git a/doc/DbsizeCommand.html b/doc/DbsizeCommand.html index 2c3e796e..d9b5b032 100644 --- a/doc/DbsizeCommand.html +++ b/doc/DbsizeCommand.html @@ -16,7 +16,7 @@
-DbsizeCommand: Contents
  DBSIZE
    Return value
    See also +DbsizeCommand: Contents
  DBSIZE
    Return value

DbsizeCommand

@@ -26,9 +26,9 @@
-

DBSIZE

Return the number of keys in the currently selected database.
-

Return value

Integer reply

See also

- + #sidebar GenericCommandsSidebar

DBSIZE

Return the number of keys in the currently selected database.
+

Return value

Integer reply +
diff --git a/doc/DelCommand.html b/doc/DelCommand.html index 3d709696..8d063ce7 100644 --- a/doc/DelCommand.html +++ b/doc/DelCommand.html @@ -16,7 +16,7 @@
-DelCommand: Contents
    Return value
    See also +DelCommand: Contents
  DEL _key1_ _key2_ ... _keyN_
    Return value

DelCommand

@@ -26,13 +26,13 @@
- = DEL key1 key2 ... keyN = + #sidebar GenericCommandsSidebar

DEL _key1_ _key2_ ... _keyN_

Time complexity: O(1)
Remove the specified keys. If a given key does not existno operation is performed for this key. The commnad returns the number ofkeys removed.

Return value

Integer reply, specifically:

 an integer greater than 0 if one or more keys were removed
 0 if none of the specified key existed
-

See also

- + +
diff --git a/doc/ExistsCommand.html b/doc/ExistsCommand.html index 32cc9978..e8279163 100644 --- a/doc/ExistsCommand.html +++ b/doc/ExistsCommand.html @@ -16,7 +16,7 @@
-ExistsCommand: Contents
  EXISTS _key_
    Return value
    See also +ExistsCommand: Contents
  EXISTS _key_
    Return value

ExistsCommand

@@ -26,13 +26,13 @@
-

EXISTS _key_

+ #sidebar GenericCommandsSidebar

EXISTS _key_

Time complexity: O(1)
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 willreturn "1".

Return value

Integer reply, specifically:

 1 if the key exists.
 0 if the key does not exist.
-

See also

- + +
diff --git a/doc/ExpireCommand.html b/doc/ExpireCommand.html index 3a78e1e2..d5baeca2 100644 --- a/doc/ExpireCommand.html +++ b/doc/ExpireCommand.html @@ -16,7 +16,7 @@

ExpireCommand

@@ -26,7 +26,7 @@
-

EXPIRE _key_ _seconds_

+ #sidebar GenericCommandsSidebar

EXPIRE _key_ _seconds_

EXPIREAT _key_ _unixtime_ (Redis >

1.1)= Time complexity: O(1)
Set a timeout on the specified key. After the timeout the key will beautomatically delete by the server. A key with an associated timeout issaid to be volatile in Redis terminology.
Voltile keys are stored on disk like the other keys, the timeout is persistenttoo like all the other aspects of the dataset. Saving a dataset containingthe dataset and stopping the server does not stop the flow of time as Redisregisters on disk when the key will no longer be available as Unix time, andnot the remaining seconds.
@@ -57,8 +57,8 @@ OK

Return value

Integer reply, specifically:

 1: the timeout was set.
 0: the timeout was not set since the key already has an associated timeout, or the key does not exist.
-

See also

- + +
diff --git a/doc/FAQ.html b/doc/FAQ.html index d87bebc3..6d0246dc 100644 --- a/doc/FAQ.html +++ b/doc/FAQ.html @@ -16,7 +16,7 @@
-FAQ: Contents
  Why I need Redis if there is already memcachedb, Tokyo Cabinet, ...?
  Isn't this key-value thing just hype?
  Can I backup a Redis DB while the server is working?
  What's the Redis memory footprint?
  I like Redis high level operations and features, but I don't like it takes everything in memory and I can't have a dataset larger the memory. Plans to change this?
  Why Redis takes the whole dataset in RAM?
  If my dataset is too big for RAM and I don't want to use consistent hashing or other ways to distribute the dataset across different nodes, what I can do to use Redis anyway?
  Do you plan to implement Virtual Memory in Redis? Why don't just let the Operating System handle it for you?
  I have an empty Redis server but INFO and logs are reporting megabytes of memory in use!
  What happens if Redis runs out of memory?
  How much time it takes to load a big database at server startup?
  Background saving is failing with a fork() error under Linux even if I've a lot of free RAM!
  Are Redis on disk snapshots atomic?
  Redis is single threaded, how can I exploit multiple CPU / cores?
  I'm using some form of key hashing for partitioning, but what about SORT BY?
  What is the maximum number of keys a single Redis instance can hold? and what the max number of elements in a List, Set, Ordered Set?
  What Redis means actually?
  Why did you started the Redis project? +FAQ: Contents
  Isn't this key-value thing just hype?
  Can I backup a Redis DB while the server is working?
  What's the Redis memory footprint?
  I like Redis high level operations and features, but I don't like it takes everything in memory and I can't have a dataset larger the memory. Plans to change this?
  Why Redis takes the whole dataset in RAM?
  If my dataset is too big for RAM and I don't want to use consistent hashing or other ways to distribute the dataset across different nodes, what I can do to use Redis anyway?
  Do you plan to implement Virtual Memory in Redis? Why don't just let the Operating System handle it for you?
  I have an empty Redis server but INFO and logs are reporting megabytes of memory in use!
  What happens if Redis runs out of memory?
  How much time it takes to load a big database at server startup?
  Background saving is failing with a fork() error under Linux even if I've a lot of free RAM!
  Are Redis on disk snapshots atomic?
  Redis is single threaded, how can I exploit multiple CPU / cores?
  I'm using some form of key hashing for partitioning, but what about SORT BY?
  What is the maximum number of keys a single Redis instance can hold? and what the max number of elements in a List, Set, Ordered Set?
  What Redis means actually?
  Why did you started the Redis project?

FAQ

@@ -26,7 +26,7 @@
-

Why I need Redis if there is already memcachedb, Tokyo Cabinet, ...?

Memcachedb is basically memcached done persistent. Redis is a different evolution + = Why I need Redis if there is already memcachedb, Tokyo Cabinet, ...? =

Memcachedb is basically memcached done persistent. Redis is a different evolution path in the key-value DBs, the idea is that the main advantages of key-value DBs are retained even without a so severe loss of comfort of plain key-value DBs. So Redis offers more features:

@@ -61,6 +61,7 @@ memory and you have a clear picture of what happens. So this means to have 10 times the I/O between memory and disk than otherwise needed.

I have an empty Redis server but INFO and logs are reporting megabytes of memory in use!

This may happen and it's prefectly ok. Redis objects are small C structures allocated and freed a lot of times. This costs a lot of CPU so instead of being freed, released objects are taken into a free list and reused when needed. This memory is taken exactly by this free objects ready to be reused.

What happens if Redis runs out of memory?

With modern operating systems malloc() returning NULL is not common, usually the server will start swapping and Redis performances will be disastrous so you'll know it's time to use more Redis servers or get more RAM.

The INFO command (work in progress in this days) will report the amount of memory Redis is using so you can write scripts that monitor your Redis servers checking for critical conditions.

You can also use the "maxmemory" option in the config file to put a limit to the memory Redis can use. If this limit is reached Redis will start to reply with an error to write commands (but will continue to accept read-only commands).

How much time it takes to load a big database at server startup?

Just an example on normal hardware: It takes about 45 seconds to restore a 2 GB database on a fairly standard system, no RAID. This can give you some kind of feeling about the order of magnitude of the time needed to load data when you restart the server.

Background saving is failing with a fork() error under Linux even if I've a lot of free RAM!

Short answer: echo 1 > /proc/sys/vm/overcommit_memory :)

And now the long one:

Redis background saving schema relies on the copy-on-write semantic of fork in modern operating systems: Redis forks (creates a child process) that is an exact copy of the parent. The child process dumps the DB on disk and finally exits. In theory the child should use as much memory as the parent being a copy, but actually thanks to the copy-on-write semantic implemented by most modern operating systems the parent and child process will share the common memory pages. A page will be duplicated only when it changes in the child or in the parent. Since in theory all the pages may change while the child process is saving, Linux can't tell in advance how much memory the child will take, so if the overcommit_memory setting is set to zero fork will fail unless there is as much free RAM as required to really duplicate all the parent memory pages, with the result that if you have a Redis dataset of 3 GB and just 2 GB of free memory it will fail.

Setting overcommit_memory to 1 says Linux to relax and perform the fork in a more optimistic allocation fashion, and this is indeed what you want for Redis.

Are Redis on disk snapshots atomic?

Yes, redis background saving process is always fork(2)ed when the server is outside of the execution of a command, so every command reported to be atomic in RAM is also atomic from the point of view of the disk snapshot.

Redis is single threaded, how can I exploit multiple CPU / cores?

Simply start multiple instances of Redis in different ports in the same box and threat them as different servers! Given that Redis is a distributed database anyway in order to scale you need to think in terms of multiple computational units. At some point a single box may not be enough anyway.

In general key-value databases are very scalable because of the property that different keys can stay on different servers independently.

In Redis there are client libraries such Redis-rb (the Ruby client) that are able to handle multiple servers automatically using consistent hashing. We are going to implement consistent hashing in all the other major client libraries. If you use a different language you can implement it yourself otherwise just hash the key before to SET / GET it from a given server. For example imagine to have N Redis servers, server-0, server-1, ..., server-N. You want to store the key "foo", what's the right server where to put "foo" in order to distribute keys evenly among different servers? Just perform the crc = CRC32("foo"), then servernum = crc % N (the rest of the division for N). This will give a number between 0 and N-1 for every key. Connect to this server and store the key. The same for gets.

This is a basic way of performing key partitioning, consistent hashing is much better and this is why after Redis 1.0 will be released we'll try to implement this in every widely used client library starting from Python and PHP (Ruby already implements this support).

I'm using some form of key hashing for partitioning, but what about SORT BY?

With SORT BY you need that all the weight keys are in the same Redis instance of the list/set you are trying to sort. In order to make this possible we developed a concept called key tags. A key tag is a special pattern inside a key that, if preset, is the only part of the key hashed in order to select the server for this key. For example in order to hash the key "foo" I simply perform the CRC32 checksum of the whole string, but if this key has a pattern in the form of the characters {...} I only hash this substring. So for example for the key "foo{bared}" the key hashing code will simply perform the CRC32 of "bared". This way using key tags you can ensure that related keys will be stored on the same Redis instance just using the same key tag for all this keys. Redis-rb already implements key tags.

What is the maximum number of keys a single Redis instance can hold? and what the max number of elements in a List, Set, Ordered Set?

In theory Redis can handle up to 232 keys, and was tested in practice to handle at least 150 million of keys per instance. We are working in order to experiment with larger values.

Every list, set, and ordered set, can hold 2
32 elements.

Actually Redis internals are ready to allow up to 264 elements but the current disk dump format don't support this, and there is a lot time to fix this issues in the future as currently even with 128 GB of RAM it's impossible to reach 232 elements.

What Redis means actually?

Redis means two things:

Why did you started the Redis project?

In order to scale LLOOGG. But after I got the basic server working I liked the idea to share the work with other guys, and Redis was turned into an open source project. +
diff --git a/doc/Features.html b/doc/Features.html index 62fa1350..66d387e1 100644 --- a/doc/Features.html +++ b/doc/Features.html @@ -26,7 +26,9 @@
-

Features (DRAFT)

Checking Redis for the first time? Here your will find the most important features, and pointers to a lot more information.

Speed

Redis is written in ANSI C, and loads the whole dataset in memory, so it is wicked fast! Up to 110,000 SETs/second, 81,000 GETs/second can be achieved in an entry level Linux box. Read more about Redis Speed.

Also Redis supports Pipelining of commands and getting and setting múltiple values in a single command to speed up communication with the client libraries.

Persistence

While all the data lives in memory, changes are asynchronously saved on disk using flexible policies based on elapsed time and/or number of updates since last save.

If you can't afford losing some data, starting on version 1.1 (currently in beta but you can download it from the Git repository) Redis supports an append-only file persistence mode. Check more on Persistence, or read the AppendOnlyFileHowto for more information.

Support for Data Structures

Values in Redis can be Strings as in a conventional key-value store, but also Lists, Sets, and OrderedSets (to be support in version 1.1). This data types allow pushing/poping elements, or adding/removing them, also perform server side union, intersection, difference between sets, and so forth depending on the types. Redis supports different kind of sorting abilities for Sets and Lists.

You can think in Redis as a Data Structures Server, that allows you to model non trivial problems. Read Data Types to learn more about the way Redis handle Strings, and the Commands supported by Lists, Sets and OrderedSets

Atomic Operations

Redis operations working on the different Data Types are atomic, so setting or increasing a key, adding and removing elements from a set, increasing a counter will all be accomplished safely.

Variety of Supported Languages

Ruby, Python, Twisted Python, PHP, Erlang, Tcl, Perl, Lua, Java, Scala, Clojure, choose your poison. Check the list of Supported Languages for all the details.

If your favorite language is not supported yet, you can write your own client library, as the Protocol is pretty simple.

Master/Slave Replication

Redis supports a very simple and fast Master/Slave replication. Is so simple it takes only one line in the configuration file to set it up, and 21 seconds for a Slave to complete the initial sync of 10 MM key set in a Amazon EC2 instance.

Read more about Master/Slave Replication.

Sharding

Distributing the dataset across multiple Redis instances is easy in Redis, as in any other key-value store. And this depends basically on the Languages client libraries being able to do so.

Read more about Sharding if you want to know more abour distributing data and workload in Redis.

Hot Backups

TODO

Simple to Install, Setup and Manage

Installing Redis requires little more than downloading it, uncompressing it and running make. Management is near zero, so you can start using Redis in a matter of minutes.

Go on and read about Redis installation, its Setup and Management.

Portable

Redis is written in ANSI C and works in most POSIX systems like Linux, BSD, Mac OS X, Solaris, and so on. Redis is reported to compile and work under WIN32 if compiled with Cygwin, but there is no official support for Windows currently.

Liberal Licensing

Redis is free software released under the very liberal BSD license.

What's next?

Want to get started with Redis? Try the Quick Start you will be up and running in just a matter of minutes.

Check the Code Samples and find how you can use Redis with your favorite programming language.

Compare Redis with other key-value stores, like Tokyo Cabinet or Memcached. + #sidebar SideBar +

Features (DRAFT)

Checking Redis for the first time? Here your will find the most important features, and pointers to a lot more information.

Speed

Redis is written in ANSI C, and loads the whole dataset in memory, so it is wicked fast! Up to 110,000 SETs/second, 81,000 GETs/second can be achieved in an entry level Linux box. Read more about Redis Speed.

Also Redis supports Pipelining of commands and getting and setting múltiple values in a single command to speed up communication with the client libraries.

Persistence

While all the data lives in memory, changes are asynchronously saved on disk using flexible policies based on elapsed time and/or number of updates since last save.

If you can't afford losing some data, starting on version 1.1 (currently in beta but you can download it from the Git repository) Redis supports an append-only file persistence mode. Check more on Persistence, or read the AppendOnlyFileHowto for more information.

Support for Data Structures

Values in Redis can be Strings as in a conventional key-value store, but also Lists, Sets, and SortedSets (to be support in version 1.1). This data types allow pushing/poping elements, or adding/removing them, also perform server side union, intersection, difference between sets, and so forth depending on the types. Redis supports different kind of sorting abilities for Sets and Lists.

You can think in Redis as a Data Structures Server, that allows you to model non trivial problems. Read Data Types to learn more about the way Redis handle Strings, and the Commands supported by Lists, Sets and SortedSets

Atomic Operations

Redis operations working on the different Data Types are atomic, so setting or increasing a key, adding and removing elements from a set, increasing a counter will all be accomplished safely.

Variety of Supported Languages

Ruby, Python, Twisted Python, PHP, Erlang, Tcl, Perl, Lua, Java, Scala, Clojure, choose your poison. Check the list of Supported Languages for all the details.

If your favorite language is not supported yet, you can write your own client library, as the Protocol is pretty simple.

Master/Slave Replication

Redis supports a very simple and fast Master/Slave replication. Is so simple it takes only one line in the configuration file to set it up, and 21 seconds for a Slave to complete the initial sync of 10 MM key set in a Amazon EC2 instance.

Read more about Master/Slave Replication.

Sharding

Distributing the dataset across multiple Redis instances is easy in Redis, as in any other key-value store. And this depends basically on the Languages client libraries being able to do so.

Read more about Sharding if you want to know more abour distributing data and workload in Redis.

Hot Backups

TODO

Simple to Install, Setup and Manage

Installing Redis requires little more than downloading it, uncompressing it and running make. Management is near zero, so you can start using Redis in a matter of minutes.

Go on and read about Redis installation, its Setup and Management.

Portable

Redis is written in ANSI C and works in most POSIX systems like Linux, BSD, Mac OS X, Solaris, and so on. Redis is reported to compile and work under WIN32 if compiled with Cygwin, but there is no official support for Windows currently.

Liberal Licensing

Redis is free software released under the very liberal BSD license.

What's next?

Want to get started with Redis? Try the Quick Start you will be up and running in just a matter of minutes.

Check the Code Samples and find how you can use Redis with your favorite programming language.

Compare Redis with other key-value stores, like Tokyo Cabinet or Memcached. +
diff --git a/doc/FlushallCommand.html b/doc/FlushallCommand.html index 85c84225..5ce99421 100644 --- a/doc/FlushallCommand.html +++ b/doc/FlushallCommand.html @@ -16,7 +16,7 @@
-FlushallCommand: Contents
  FLUSHALL
    Return value
    See also +FlushallCommand: Contents
  FLUSHALL
    Return value

FlushallCommand

@@ -26,10 +26,10 @@
-

FLUSHALL

+ #sidebar GenericCommandsSidebar

FLUSHALL

Delete all the keys of all the existing databases, not just the currently selected one. This command never fails.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/FlushdbCommand.html b/doc/FlushdbCommand.html index 6bf4ca04..53217350 100644 --- a/doc/FlushdbCommand.html +++ b/doc/FlushdbCommand.html @@ -16,7 +16,7 @@
-FlushdbCommand: Contents
  FLUSHDB
    Return value
    See also +FlushdbCommand: Contents
  FLUSHDB
    Return value

FlushdbCommand

@@ -26,10 +26,10 @@
-

FLUSHDB

+ #sidebar GenericCommandsSidebar

FLUSHDB

Delete all the keys of the currently selected DB. This command never fails.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/FromSqlToDataStructures.html b/doc/FromSqlToDataStructures.html index bdfdb278..4a837dfd 100644 --- a/doc/FromSqlToDataStructures.html +++ b/doc/FromSqlToDataStructures.html @@ -27,7 +27,7 @@
-

Introduction (IDEA MORE THAN A DRAFT)

¿Coming from SQLand? ¿Who doesn't? Redis is simple, primitive when comapred to the world you are used to in the world of Relational Database Managers (RDBMS) and Structure Query Language (SQL), here you will find insight to build bridges between both worlds to model real life problems.

Data Structures

When I was young, happy and single ;) I studied Data Structures at the university, actually I learnt Data Structures and Algorithms before learning anything about Databases, and particularly RDBMS and SQL. This is natural because you need to know about Data Structures and Algorithms to understand a Database.

Redis can be seen as a Data Structures Server, a very simple interface to a extremly fast and efficient

Dude where is my SELECT statement?

LISTs

In SQL there is no such thing as a "natural" order, a SELECT statement without a ORDER BY clause will return data in a undefined order. In Redis LISTs address the problem of natural ordering, ...

SETs

So you have a bunch of unordered data,

SORT to the rescue

But sometimes we need to actually sort a LIST in a order different from its natural or take a SET and have it ordered, there is where the fast SORT commands comes handy...

SORT BY

Just SORTing keys would be kind of boring, sometimes useless right? Well, you can SORT...

HASHEs

Umm, sorry you will have to wait for a upcoming version of Redis to have Hashes, but here are Idioms you should house to manage Dictionary like data... +

Introduction (IDEA MORE THAN A DRAFT)

¿Coming from SQLand? ¿Who doesn't? Redis is simple, primitive when comapred to the world you are used to in the world of Relational Database Managers (RDBMS) and Structure Query Language (SQL), here you will find insight to build bridges between both worlds to model real life problems.

Data Structures

When I was young, happy and single ;) I studied Data Structures at the university, actually I learnt Data Structures and Algorithms before learning anything about Databases, and particularly RDBMS and SQL. This is natural because you need to know about Data Structures and Algorithms to understand a Database.

Redis can be seen as a Data Structures Server, a very simple interface to a extremly fast and efficient

Dude where is my SELECT statement?

LISTs

In SQL there is no such thing as a "natural" order, a SELECT statement without a ORDER BY clause will return data in a undefined order. In Redis LISTs address the problem of natural ordering, ...

SETs

So you have a bunch of unordered data,

SORT to the rescue

But sometimes we need to actually sort a LIST in a order different from its natural or take a SET and have it ordered, there is where the fast SORT commands comes handy...

SORT BY

Just SORTing keys would be kind of boring, sometimes useless right? Well, you can SORT...

HASHEs

Umm, sorry you will have to wait for a upcoming version of Redis to have Hashes, but here are Idioms you should house to manage Dictionary like data...
diff --git a/doc/GenericCommandsSidebar.html b/doc/GenericCommandsSidebar.html new file mode 100644 index 00000000..d2dd6aa7 --- /dev/null +++ b/doc/GenericCommandsSidebar.html @@ -0,0 +1,36 @@ + + + + + + + +
+ + + +
+
+ +GenericCommandsSidebar: Contents +
+ +

GenericCommandsSidebar

+ +
+ +
+ + + +
+
+ + + diff --git a/doc/GetCommand.html b/doc/GetCommand.html index 50d6bf34..69083552 100644 --- a/doc/GetCommand.html +++ b/doc/GetCommand.html @@ -16,7 +16,7 @@
-GetCommand: Contents
  GET _key_
    Return value
    See also +GetCommand: Contents
  GET _key_
    Return value

GetCommand

@@ -26,10 +26,10 @@
-

GET _key_

+ #sidebar StringCommandsSidebar

GET _key_

Time complexity: O(1)
Get the value of the specified key. If the keydoes not exist the special value 'nil' is returned.If the value stored at key is not a string an erroris returned because GET can only handle string values.
-

Return value

Bulk reply

See also

- +

Return value

Bulk reply +
diff --git a/doc/GetsetCommand.html b/doc/GetsetCommand.html index e1d8d538..1726bccc 100644 --- a/doc/GetsetCommand.html +++ b/doc/GetsetCommand.html @@ -16,7 +16,7 @@
-GetsetCommand: Contents
  GETSET _key_ _value_
    Return value
    Design patterns
    See also +GetsetCommand: Contents
  GETSET _key_ _value_
    Return value
    Design patterns

GetsetCommand

@@ -26,11 +26,9 @@
-

GETSET _key_ _value_

+ #sidebar StringCommandsSidebar

GETSET _key_ _value_

Time complexity: O(1)
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 whena given condition arises. For example a process may call INCR against thekey mycounter every time some event occurred, but from time totime we need to get the value of the counter and reset it to zero atomicallyusing GETSET mycounter 0.
-

See also

-
diff --git a/doc/IncrCommand.html b/doc/IncrCommand.html index 676d06cb..b2b35499 100644 --- a/doc/IncrCommand.html +++ b/doc/IncrCommand.html @@ -16,7 +16,7 @@

IncrCommand

@@ -26,14 +26,15 @@
-

INCR _key_

+ #sidebar StringCommandsSidebar

INCR _key_

INCRBY _key_ _integer_

DECR _key_ _integer_

DECRBY _key_ _integer_

Time complexity: O(1)
Increment or decrement the number stored at key by one. If the key doesnot exist or contains a value of a wrong type, set the key to thevalue of "0" before to perform the increment or decrement operation.
INCRBY and DECRBY work just like INCR and DECR but instead toincrement/decrement by 1 the increment/decrement is integer.
-

Return value

Integer reply, this commands will reply with the new value of key after the increment or decrement.

See also

- +
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. +
diff --git a/doc/InfoCommand.html b/doc/InfoCommand.html index 325deff4..dd689acd 100644 --- a/doc/InfoCommand.html +++ b/doc/InfoCommand.html @@ -16,7 +16,7 @@
-InfoCommand: Contents
  INFO
    Return value
    Notes
    See also +InfoCommand: Contents
  INFO
    Return value
    Notes

InfoCommand

@@ -26,7 +26,7 @@
-

INFO

The info command returns different information and statistics about the server in an format that's simple to parse by computers and easy to red by huamns.
+ #sidebar ControlCommandsSidebar

INFO

The info command returns different information and statistics about the server in an format that's simple to parse by computers and easy to red by huamns.

Return value

Bulk reply, specifically in the following format:

 edis_version:0.07
 connected_clients:1
@@ -39,8 +39,6 @@ total_commands_processed:1
 uptime_in_seconds:25
 uptime_in_days:0
 
All the fields are in the form field:value

Notes

-

See also

-
diff --git a/doc/IntroductionToRedisDataTypes.html b/doc/IntroductionToRedisDataTypes.html new file mode 100644 index 00000000..2bba4091 --- /dev/null +++ b/doc/IntroductionToRedisDataTypes.html @@ -0,0 +1,151 @@ + + + + + + + +
+ + + +
+ + +

IntroductionToRedisDataTypes

+ +
+ +
+ +
+ = A fifteen minutes introduction to Redis data types =

As you already probably know Redis is not a plain key-value store, actually it is a data structures server, supporting different kind of values. That is, you can't just set strings as values of keys. All the following data types are supported as values:

  • Binary-safe strings.
  • Lists of binary-safe strings.
  • Sets of binary-safe strings, that are collection of unique unsorted elements. You can think at this as a Ruby hash where all the keys are set to the 'true' value.
  • Sorted sets, similar to Sets but where every element is associated to a floating number score. The elements are taken sorted by score. You can think at this as Ruby hashes where the key is the element and the value is the score, but where elements are always taken in order without requiring a sorting operation.
+It's not always trivial to grasp how this data types work and what to use in order to solve a given problem from the Redis command reference, so this document is a crash course to Redis data types and their most used patterns.

For all the examples we'll use the redis-cli utility, that's a simple but handy command line utility to issue commands against the Redis server.

Redis keys

Before to start talking about the different kind of values supported by Redis it is better to start saying that keys are not binary safe strings in Redis, but just strings not containing a space or a newline character. For instance "foo" or "123456789" or "foo_bar" are valid keys, while "hello world" or "hello\n" are not.

Actually there is nothing inside the Redis internals preventing the use of binary keys, it's just a matter of protocol, and actually the new protocol introduced with Redis 1.2 (1.2 betas are 1.1.x) in order to implement commands like MSET, is totally binary safe. Still for now consider this as an hard limit as the database is only tested with "normal" keys.

A few other rules about keys:

  • Too long keys are not a good idea, for instance a key of 1024 bytes is not a good idea not only memory-wise, but also because the lookup of the key in the dataset may require several costly key-comparisons.
  • Too short keys are not a good idea. There is no point in writing "u:1000:pwd" as key if you can write instead "user:1000:password", the latter is more readable and the added space is very little compared to the space used by the key object itself.
  • Try to stick with a schema. For instance "object-type:id:field" can be a nice idea, like in "user:1000:password". I like to use dots for multi-words fields, like in "comment:1234:reply.to".
+

The string type

This is the simplest Redis type. If you use only this type, Redis will be something like a memcached server with persistence.

Let's play a bit with the string type:

+$ ./redis-cli set mykey "my binary safe value"
+OK
+$ ./redis-cli get mykey
+my binary safe value
+
As you can see using the Set command and the Get command is trivial to set values to strings and have this strings returned back.

Values can be strings (including binary data) of every kind, for instance you can store a jpeg image inside a key. A value can't be bigger than 1 Gigabyte.

Even if strings are the basic values of Redis, there are interesting operations you can perform against them. For instance one is atomic increment:

+$ ./redis-cli set counter 100
+OK
+$ ./redis-cli incr counter
+(integer) 101
+$ ./redis-cli incr counter
+(integer) 102
+$ ./redis-cli incrby counter 10
+(integer) 112
+
The INCR command parses the string value as an integer, increments it by one, and finally sets the obtained value as the new string value. There are other similar commands like INCRBY, DECR and DECRBY. Actually internally it's always the same command, acting in a slightly different way.

What means that INCR is atomic? That even multiple clients issuing INCR against the same key will never incur into a race condition. For instance it can't never happen that client 1 read "10", client 2 read "10" at the same time, both increment to 11, and set the new value of 11. The final value will always be of 12 ad the read-increment-set operation is performed while all the other clients are not executing a command at the same time.

Another interesting operation on string is the GETSET command, that does just what its name suggests: Set a key to a new value, returning the old value, as result. Why this is useful? Example: you have a system that increments a Redis key using the INCR command every time your web site receives a new visit. You want to collect this information one time every hour, without loosing a single key. You can GETSET the key assigning it the new value of "0" and reading the old value back.

The List type

To explain the List data type it's better to start with a little of theory, as the term List is often used in an improper way by information technology folks. For instance "Python Lists" are not what the name may suggest (Linked Lists), but them are actually Arrays (the same data type is called Array in Ruby actually).

From a very general point of view a List is just a sequence of ordered elements: 10,20,1,2,3 is a list, but when a list of items is implemented using an Array and when instead a Linked List is used for the implementation, the properties change a lot.

Redis lists are implemented via Linked Lists, this means that even if you have million of elements inside a list, the operation of adding a new element in the head or in the tail of the list is performed in constant time. Adding a new element with the LPOP command to the head of a ten elements list is the same speed as adding an element to the head of a 10 million elements list.

What's the downside? That accessing an element by index is very fast in lists implemented with an Array and not so fast in lists implemented by linked lists.

Redis Lists are implemented with linked lists because for a database system is crucial to be able to add elements to a very long list in a very fast way. Another strong advantage is, as you'll see in a moment, that Redis Lists can be taken at constant length in constant time.

First steps with Redis lists

The LPUSH command add a new element into a list, on the left (on head), while the RPUSH command add a new element into alist, ot the right (on tail). Finally the LRANGE command extract ranges of elements from lists:

+$ ./redis-cli rpush messages "Hello how are you?"
+OK
+$ ./redis-cli rpush messages "Fine thanks. I'm having fun with Redis"
+OK
+$ ./redis-cli rpush messages "I should look into this NOSQL thing ASAP"
+OK
+$ ./redis-cli lrange messages 0 2
+1. Hello how are you?
+2. Fine thanks. I'm having fun with Redis
+3. I should look into this NOSQL thing ASAP
+
Note that LRANGE takes two indexes, the first and the last element of the range to return. Both the indexes can be negative to tell Redis to start to count for the end, so -1 is the last element, -2 is the penultimate element of the list, and so forth.

As you can guess from the example above, lists can be used, for instance, in order to implement a chat system. Another use is as queues in order to route messages between different processes. But the key point is that you can use Redis lists every time you require to access data in the same order they are added. This will not require any SQL ORDER BY operation, will be very fast, and will scale to millions of elements even with a toy Linux box.

For instance in ranking systems like the social news reddit.com you can add every new submitted link into a List, and with LRANGE it's possible to paginate results in a trivial way.

In a blog engine implementation you can have a list for every post, where to push blog comments, and so forth.

Pushing IDs instead of the actual data in Redis lists

In the above example we pushed our "objects" (simply messages in the example) directly inside the Redis list, but this is often not the way to go, as objects can be referenced in multiple times: in a list to preserve their chronological order, in a Set to remember they are about a specific category, in another list but only if this object matches some kind of requisite, and so forth.

Let's return back to the reddit.com example. A more credible pattern for adding submitted links (news) to the list is the following:

+$ ./redis-cli incr next.news.id
+(integer) 1
+$ ./redis-cli set news:1:title "Redis is simple"
+OK
+$ ./redis-cli set news:1:url "http://code.google.com/p/redis"
+OK
+$ ./redis-cli lpush submitted.news 1
+OK
+
We obtained an unique incremental ID for our news object just incrementing a key, then used this ID to create the object setting a key for every field in the object. Finally the ID of the new object was pushed on the submitted.news list.

This is just the start. Check the Command Reference and read about all the other list related commands. You can remove elements, rotate lists, get and set elements by index, and of course retrieve the length of the list with LLEN.

Redis Sets

Redis Sets are unordered collection of binary-safe strings. The SADD command adds a new element to a set. It's also possible to do a number of other operations against sets like testing if a given element already exists, performing the intersection, union or difference between multiple sets and so forth. An example is worth 1000 words:

+$ ./redis-cli sadd myset 1
+(integer) 1
+$ ./redis-cli sadd myset 2
+(integer) 1
+$ ./redis-cli sadd myset 3
+(integer) 1
+$ ./redis-cli smembers myset
+1. 3
+2. 1
+3. 2
+
I added three elements to my set and told Redis to return back all the elements. As you can see they are not sorted.

Now let's check if a given element exists:

+$ ./redis-cli sismember myset 3
+(integer) 1
+$ ./redis-cli sismember myset 30
+(integer) 0
+
"3" is a member of the set, while "30" is not. Sets are very good in order to express relations between objects. For instance we can easily Redis Sets in order to implement tags.

A simple way to model this is to have, for every object you want to tag, a Set with all the IDs of the tags associated with the object, and for every tag that exists, a Set of of all the objects tagged with this tag.

For instance if our news ID 1000 is tagged with tag 1,2,5 and 77, we can specify the following two Sets:

+$ ./redis-cli sadd news:1000:tags 1
+(integer) 1
+$ ./redis-cli sadd news:1000:tags 2
+(integer) 1
+$ ./redis-cli sadd news:1000:tags 5
+(integer) 1
+$ ./redis-cli sadd news:1000:tags 77
+(integer) 1
+$ ./redis-cli sadd tag:1:objects 1000
+(integer) 1
+$ ./redis-cli sadd tag:2:objects 1000
+(integer) 1
+$ ./redis-cli sadd tag:5:objects 1000
+(integer) 1
+$ ./redis-cli sadd tag:77:objects 1000
+(integer) 1
+
To get all the tags for a given object is trivial:

$ ./redis-cli smembers news:1000:tags +1. 5 +2. 1 +3. 77 +4. 2

But there are other non trivial operations that are still easy to implement using the right Redis commands. For instance we may want the list of all the objects having as tags 1, 2, 10, and 27 at the same time. We can do this using the SinterCommand that performs the intersection between different sets. So in order to reach our goal we can just use:

+$ ./redis-cli sinter tag:1:objects tag:2:objects tag:10:objects tag:27:objects
+... no result in our dataset composed of just one object ;) ...
+
Look at the Command Reference to discover other Set related commands, there are a bunch of interesting one. Also make sure to check the SORT command as both Redis Sets and Lists are sortable.

A digression. How to get unique identifiers for strings

In our tags example we showed tag IDs without to mention how this IDs can be obtained. Basically for every tag added to the system, you need an unique identifier. You also want to be sure that there are no race conditions if multiple clients are trying to add the same tag at the same time. Also, if a tag already exists, you want its ID returned, otherwise a new unique ID should be created and associated to the tag.

Redis 1.4 will add the Hash type. With it it will be trivial to associate strings with unique IDs, but how to do this today with the current commands exported by Redis in a reliable way?

Our first attempt (that is broken) can be the following. Let's suppose we want to get an unique ID for the tag "redis":

  • In order to make this algorithm binary safe (they are just tags but think to utf8, spaces and so forth) we start performing the SHA1 sum of the tag. SHA1(redis) = b840fc02d524045429941cc15f59e41cb7be6c52.
  • Let's check if this tag is already associated with an unique ID with the command GET tag:b840fc02d524045429941cc15f59e41cb7be6c52:id.
  • If the above GET returns an ID, return it back to the user. We already have the unique ID.
  • Otherwise... create a new unique ID with INCR next.tag.id (assume it returned 123456).
  • Finally associate this new ID to our tag with SET tag:b840fc02d524045429941cc15f59e41cb7be6c52:id 123456 and return the new ID to the caller.
+Nice. Or better.. broken! What about if two clients perform this commands at the same time trying to get the unique ID for the tag "redis"? If the timing is right they'll both get nil from the GET operation, will both increment the next.tag.id key and will set two times the key. One of the two clients will return the wrong ID to the caller. To fix the algorithm is not hard fortunately, and this is the sane version:

  • In order to make this algorithm binary safe (they are just tags but think to utf8, spaces and so forth) we start performing the SHA1 sum of the tag. SHA1(redis) = b840fc02d524045429941cc15f59e41cb7be6c52.
  • Let's check if this tag is already associated with an unique ID with the command GET tag:b840fc02d524045429941cc15f59e41cb7be6c52:id.
  • If the above GET returns an ID, return it back to the user. We already have the unique ID.
  • Otherwise... create a new unique ID with INCR next.tag.id (assume it returned 123456).
  • Finally associate this new ID to our tag with SETNX tag:b840fc02d524045429941cc15f59e41cb7be6c52:id 123456. By using SETNX if a different client was faster than this one the key wil not be setted. Not only, SETNX returns 1 if the key is set, 0 otherwise. So... let's add a final step to our computation.
  • If SETNX returned 1 (We set the key) return 123456 to the caller, it's our tag ID, otherwise perform GET tag:b840fc02d524045429941cc15f59e41cb7be6c52:id and return the value to the caller.
+

Sorted sets

Sets are a very handy data type, but... they are a bit too unsorted in order to fit well for a number of problems ;) This is why Redis 1.2 introduced Sorted Sets. They are very similar to Sets, collections of binary-safe strings, but this time with an associated score, and an operation similar to the List LRANGE operation to return items in order, but working against Sorted Sets, that is, the ZRANGE command.

Basically Sorted Sets are in some way the Redis equivalent of Indexes in the SQL world. For instance in our reddit.com example above there was no mention about how to generate the actual home page with news raked by user votes and time. We'll see how sorted sets can fix this problem, but it's better to start with something simpler, illustrating the basic working of this advanced data type. Let's add a few selected hackers with their year of birth as "score".

+$ ./redis-cli zadd hackers 1940 "Alan Kay"
+(integer) 1
+$ ./redis-cli zadd hackers 1953 "Richard Stallman"
+(integer) 1
+$ ./redis-cli zadd hackers 1965 "Yukihiro Matsumoto"
+(integer) 1
+$ ./redis-cli zadd hackers 1916 "Claude Shannon"
+(integer) 1
+$ ./redis-cli zadd hackers 1969 "Linus Torvalds"
+(integer) 1
+$ ./redis-cli zadd hackers 1912 "Alan Turing"
+(integer) 1
+
For sorted sets it's a joke to return these hackers sorted by their birth year because actually they are already sorted. Sorted sets are implemented via a dual-ported data structure containing both a skip list and an hash table, so every time we add an element Redis performs an O(log(N)) operation, that's good, but when we ask for sorted elements Redis does not have to do any work at all, it's already all sorted:

+$ ./redis-cli zrange hackers 0 -1
+1. Alan Turing
+2. Claude Shannon
+3. Alan Kay
+4. Richard Stallman
+5. Yukihiro Matsumoto
+6. Linus Torvalds
+
Didn't know that Linus was younger than Yukihiro btw ;)

Anyway I want to order this elements the other way around, using ZrangeCommand instead of ZrangeCommand this time:

+$ ./redis-cli zrevrange hackers 0 -1
+1. Linus Torvalds
+2. Yukihiro Matsumoto
+3. Richard Stallman
+4. Alan Kay
+5. Claude Shannon
+6. Alan Turing
+
A very important note, ZSets have just a "default" ordering but you are still free to call the SORT command against sorted sets to get a different ordering (but this time the server will waste CPU). An alternative for having multiple orders is to add every element in multiple sorted sets at the same time.

Operating on ranges

Sorted sets are more powerful than this. They can operate on ranges. For instance let's try to get all the individuals that born up to the 1950. We use the ZRANGEBYSCORE command to do it:

+$ ./redis-cli zrangebyscore hackers -inf 1950
+1. Alan Turing
+2. Claude Shannon
+3. Alan Kay
+
We asked Redis to return all the elements with a score between negative infinite and 1950 (both extremes are included).

It's also possible to remove ranges of elements. For instance let's remove all the hackers born between 1940 and 1960 from the sorted set:

+$ ./redis-cli zremrangebyscore hackers 1940 1960
+(integer) 2
+
ZREMRANGEBYSCORE is not the best command name, but it can be very useful, and returns the number of removed elements.

Back to the reddit example

For the last time, back to the Reddit example. Now we have a decent plan to populate a sorted set in order to generate the home page. A sorted set can contain all the news that are not older than a few days (we remove old entries from time to time using ZREMRANGEBYSCORE). A background job gets all the elements from this sorted set, get the user votes and the time of the news, and compute the score to populate the reddit.home.page sorted set with the news IDs and associated scores. To show the home page we have just to perform a blazingly fast call to ZRANGE.

From time to time we'll remove too old news from the reddit.home.page sorted set as well in order for our system to work always against a limited set of news.

Updating the scores of a sorted set

Just a final note before to finish this tutorial. Sorted sets scores can be updated at any time. Just calling again ZADD against an element already included in the sorted set will update its score (and position) in O(log(N)), so sorted sets are suitable even when there are tons of updates.

This tutorial is in no way complete, this is just the basics to get started with Redis, read the Command Reference to discover a lot more.

Thanks for reading. Salvatore. +
+ +
+
+ + + diff --git a/doc/KeysCommand.html b/doc/KeysCommand.html index 98718fc0..0b64d1a8 100644 --- a/doc/KeysCommand.html +++ b/doc/KeysCommand.html @@ -16,7 +16,7 @@
-KeysCommand: Contents
  KEYS _pattern_
    Return value
    See also +KeysCommand: Contents
  KEYS _pattern_
    Return value

KeysCommand

@@ -26,13 +26,13 @@
-

KEYS _pattern_

+ #sidebar GenericCommandsSidebar

KEYS _pattern_

Time complexity: O(n) (with n being the number of keys in the DB, and assuming keys and pattern of limited length)
Returns all the keys matching the glob-style pattern asspace separated strings. For example if you have in thedatabase the keys "foo" and "foobar" the command "KEYS foo*"will return "foo foobar".
Note that while the time complexity for this operation is O(n)the constant times are pretty low. For example Redis runningon an entry level laptop can scan a 1 million keys databasein 40 milliseconds. Still it's better to consider this one ofthe slow commands that may ruin the DB performance if not usedwith care.
Glob style patterns examples: +
* haello 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). +
diff --git a/doc/LastsaveCommand.html b/doc/LastsaveCommand.html index c10b8024..67b1f66f 100644 --- a/doc/LastsaveCommand.html +++ b/doc/LastsaveCommand.html @@ -16,7 +16,7 @@
-LastsaveCommand: Contents
  LASTSAVE
    Return value
    See also +LastsaveCommand: Contents
  LASTSAVE
    Return value

LastsaveCommand

@@ -26,10 +26,10 @@
-

LASTSAVE

+ #sidebar ControlCommandsSidebar

LASTSAVE

Return the UNIX TIME of the last DB save executed with success.A client may check if a BGSAVE command succeeded reading the LASTSAVEvalue, then issuing a BGSAVE command and checking at regular intervalsevery N seconds if LASTSAVE changed.
-

Return value

Integer reply, specifically an UNIX time stamp.

See also

- +

Return value

Integer reply, specifically an UNIX time stamp. +
diff --git a/doc/LindexCommand.html b/doc/LindexCommand.html index 3bc903bb..4af80530 100644 --- a/doc/LindexCommand.html +++ b/doc/LindexCommand.html @@ -16,7 +16,7 @@
-LindexCommand: Contents
  LINDEX _key_ _index_
    Return value
    See also +LindexCommand: Contents
  LINDEX _key_ _index_
    Return value

LindexCommand

@@ -26,12 +26,12 @@
-

LINDEX _key_ _index_

+ #sidebar ListCommandsSidebar

LINDEX _key_ _index_

Time complexity: O(n) (with n being the length of the list)
Return the specified element of the list stored at the specifiedkey. 0 is the first element, 1 the second and so on. Negative indexesare supported, for example -1 is the last element, -2 the penultimateand 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 forthe first or the last element of the list is O(1).
-

Return value

Bulk reply, specifically the requested element.

See also

- +

Return value

Bulk reply, specifically the requested element. +
diff --git a/doc/ListCommandsSidebar.html b/doc/ListCommandsSidebar.html new file mode 100644 index 00000000..c570530f --- /dev/null +++ b/doc/ListCommandsSidebar.html @@ -0,0 +1,36 @@ + + + + + + + +
+ + + +
+
+ +ListCommandsSidebar: Contents +
+ +

ListCommandsSidebar

+ +
+ +
+ +
+ == List Commands ==

+
+ +
+
+ + + diff --git a/doc/Lists.html b/doc/Lists.html new file mode 100644 index 00000000..a79d9fd9 --- /dev/null +++ b/doc/Lists.html @@ -0,0 +1,43 @@ + + + + + + + +
+ + + +
+
+ +Lists: Contents
  Redis List Type
  Implementation details +
+ +

Lists

+ +
+ +
+ +
+ #sidebar ListCommandsSidebar

Redis List Type

Redis Lists are lists of Redis Strings, sorted by insertion order. It's possible to add elements to a Redis List pushing new elements on the head (on the left) or on the tail (on the right) of the list.

The LPUSH command inserts a new elmenet on head, while RPUSH inserts a new element on tail. A new list is created when one of this operations is performed against an empty key.

For instance if perform the following operations: +
+LPUSH mylist a   # now the list is "a"
+LPUSH mylist b   # now the list is "b","a"
+RPUSH mylist c   # now the list is "b","a","c" (RPUSH was used this time)
+
+The resulting list stored at mylist will contain the elements "b","a","c".

The max length of a list is 232-1 elements (4294967295, more than 4 billion of elements per list).

Implementation details

Redis Lists are implemented as doubly liked lists. A few commands benefit from the fact the lists are doubly linked in order to reach the needed element starting from the nearest extreme (head or tail). LRANGE and LINDEX are examples of such commands.

The use of linked lists also guarantees that regardless of the length of the list pushing and popping are O(1) operations.

Redis Lists cache length information so LLEN is O(1) as well. + +
+ +
+
+ + + diff --git a/doc/LlenCommand.html b/doc/LlenCommand.html index df9f4a06..07072a42 100644 --- a/doc/LlenCommand.html +++ b/doc/LlenCommand.html @@ -16,7 +16,7 @@
-LlenCommand: Contents
  LLEN _key_
    Return value
    See also +LlenCommand: Contents
  LLEN _key_
    Return value

LlenCommand

@@ -26,12 +26,12 @@
-

LLEN _key_

+ #sidebar ListCommandsSidebar

LLEN _key_

Time complexity: O(1)
Return the length of the list stored at the specified key. If thekey does not exist zero is returned (the same behaviour as forempty lists). If the value stored at key is not a list an error is returned.

Return value

Integer reply, specifically:

 The length of the list.
-

See also

- + +
diff --git a/doc/LpopCommand.html b/doc/LpopCommand.html index 02f26c93..58dffb93 100644 --- a/doc/LpopCommand.html +++ b/doc/LpopCommand.html @@ -16,7 +16,7 @@
-LpopCommand: Contents
  LPOP _key_
  RPOP _key_
    Return value
    See also +LpopCommand: Contents
  LPOP _key_
  RPOP _key_
    Return value

LpopCommand

@@ -26,12 +26,12 @@
-

LPOP _key_

+ #sidebar ListCommandsSidebar

LPOP _key_

RPOP _key_

Time complexity: O(1)
Atomically return and remove the first (LPOP) or last (RPOP) elementof the list. For example if the list contains the elements "a","b","c" LPOPwill return "a" and the list will become "b","c".
If the key does not exist or the list is already empty the specialvalue 'nil' is returned.
-

Return value

Bulk reply

See also

- +

Return value

Bulk reply +
diff --git a/doc/LrangeCommand.html b/doc/LrangeCommand.html index deffd10a..293d8e8c 100644 --- a/doc/LrangeCommand.html +++ b/doc/LrangeCommand.html @@ -16,7 +16,7 @@
-LrangeCommand: Contents
  LRANGE _key_ _start_ _end_
    Return value
    See also +LrangeCommand: Contents
  LRANGE _key_ _start_ _end_
    Return value

LrangeCommand

@@ -26,13 +26,13 @@
-

LRANGE _key_ _start_ _end_

+ #sidebar ListCommandsSidebar

LRANGE _key_ _start_ _end_

Time complexity: O(n) (with n being the length of the range)
Return the specified elements of the list stored at the specifiedkey. Start and end are zero-based indexes. 0 is the first elementof the list (the list head), 1 the next element and so on.
For example LRANGE foobar 0 2 will return the first three elementsof the list.
_start_ and end can also be negative numbers indicating offsetsfrom the end of the list. For example -1 is the last element ofthe list, -2 the penultimate element and so on.
Indexes out of range will not produce an error: if start is overthe end of the list, or start > end, an empty list is returned.If end is over the end of the list Redis will threat it just likethe last element of the list.
-

Return value

Multi bulk reply, specifically a list of elements in the specified range.

See also

- +

Return value

Multi bulk reply, specifically a list of elements in the specified range. +
diff --git a/doc/LremCommand.html b/doc/LremCommand.html index 0d7a70c4..142160f0 100644 --- a/doc/LremCommand.html +++ b/doc/LremCommand.html @@ -16,7 +16,7 @@
-LremCommand: Contents
  LREM _key_ _count_ _value_
    Return value
    See also +LremCommand: Contents
  LREM _key_ _count_ _value_
    Return value

LremCommand

@@ -26,12 +26,12 @@
-

LREM _key_ _count_ _value_

+ #sidebar ListCommandsSidebar

LREM _key_ _count_ _value_

Time complexity: O(N) (with N being the length of the list)
Remove the first count occurrences of the value element from the list.If count is zero all the elements are removed. If count is negativeelements are removed from tail to head, instead to go from head to tailthat 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) willlave the list (a,b,c,hello,x). The number of removed elements is returnedas an integer, see below for more information about the returned value.Note that non existing keys are considered like empty lists by LREM, so LREMagainst non existing keys will always return 0.

Return value

Integer Reply, specifically:

 The number of removed elements if the operation succeeded
-

See also

- + +
diff --git a/doc/LsetCommand.html b/doc/LsetCommand.html index 61d83c3b..39afd5ab 100644 --- a/doc/LsetCommand.html +++ b/doc/LsetCommand.html @@ -16,7 +16,7 @@
-LsetCommand: Contents
  LSET _key_ _index_ _value_
    Return value
    See also +LsetCommand: Contents
  LSET _key_ _index_ _value_
    Return value

LsetCommand

@@ -26,10 +26,10 @@
-

LSET _key_ _index_ _value_

+ #sidebar ListCommandsSidebar

LSET _key_ _index_ _value_

Time complexity: O(N) (with N being the length of the list)
Set the list element at index (see LINDEX for information about the_index_ argument) with the new value. Out of range indexes willgenerate an error. Note that setting the first or last elements ofthe list is O(1).
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/LtrimCommand.html b/doc/LtrimCommand.html index 7dce582a..08d3231a 100644 --- a/doc/LtrimCommand.html +++ b/doc/LtrimCommand.html @@ -16,7 +16,7 @@
-LtrimCommand: Contents
  LTRIM _key_ _start_ _end_
    Return value
    See also +LtrimCommand: Contents
  LTRIM _key_ _start_ _end_
    Return value

LtrimCommand

@@ -26,7 +26,7 @@
-

LTRIM _key_ _start_ _end_

+ #sidebar ListCommandsSidebar

LTRIM _key_ _start_ _end_

Time complexity: O(n) (with n being len of list - len of range)
Trim an existing list so that it will contain only the specifiedrange of elements specified. Start and end are zero-based indexes.0 is the first element of the list (the list head), 1 the next elementand so on.
For example LTRIM foobar 0 2 will modify the list stored at foobarkey so that only the first three elements of the list will remain.
_start_ and end can also be negative numbers indicating offsetsfrom the end of the list. For example -1 is the last element ofthe list, -2 the penultimate element and so on.
@@ -36,8 +36,8 @@ LPUSH mylist <someelement> LTRIM mylist 0 99
The above two commands will push elements in the list taking care thatthe list will not grow without limits. This is very useful when usingRedis to store logs for example. It is important to note that when usedin this way LTRIM is an O(1) operation because in the average casejust one element is removed from the tail of the list.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/MgetCommand.html b/doc/MgetCommand.html index 0e8120f2..0c716907 100644 --- a/doc/MgetCommand.html +++ b/doc/MgetCommand.html @@ -16,7 +16,7 @@
-MgetCommand: Contents
  MGET _key1_ _key2_ ... _keyN_
    Return value
    Example
    See also +MgetCommand: Contents
  MGET _key1_ _key2_ ... _keyN_
    Return value
    Example

MgetCommand

@@ -26,7 +26,7 @@
-

MGET _key1_ _key2_ ... _keyN_

+ #sidebar StringCommandsSidebar

MGET _key1_ _key2_ ... _keyN_

Time complexity: O(1) for every key
Get the values of all the specified keys. If one or more keys dont existor is not of type String, a 'nil' value is returned instead of the valueof the specified key, but the operation never fails.

Return value

Multi bulk reply

Example

 $ ./redis-cli set foo 1000
@@ -41,8 +41,8 @@ $ ./redis-cli mget foo bar nokey
 2. 2000
 3. (nil)
 $ 
-

See also

- + +
diff --git a/doc/MonitorCommand.html b/doc/MonitorCommand.html index 645968e6..1abe72b6 100644 --- a/doc/MonitorCommand.html +++ b/doc/MonitorCommand.html @@ -16,7 +16,7 @@
-MonitorCommand: Contents
  MONITOR
    Return value
    See also +MonitorCommand: Contents
  MONITOR
    Return value

MonitorCommand

@@ -26,7 +26,7 @@
-

MONITOR

MONITOR is a debugging command that outputs the whole sequence of commandsreceived by the Redis server. is very handy in order to understandwhat is happening into the database. This command is used directlyvia telnet.
+ #sidebar ControlCommandsSidebar

MONITOR

MONITOR is a debugging command that outputs the whole sequence of commandsreceived by the Redis server. is very handy in order to understandwhat is happening into the database. This command is used directlyvia telnet.
 % telnet 127.0.0.1 6379
 Trying 127.0.0.1...
@@ -52,8 +52,8 @@ set foo_a 5
 hello
 
The ability to see all the requests processed by the server is useful in orderto spot bugs in the application both when using Redis as a database and asa distributed caching system.
In order to end a monitoring session just issue a QUIT command by hand.
-

Return value

Non standard return value, just dumps the received commands in an infinite flow.

See also

- +

Return value

Non standard return value, just dumps the received commands in an infinite flow. +
diff --git a/doc/MoveCommand.html b/doc/MoveCommand.html index db14f4bf..3bab67d0 100644 --- a/doc/MoveCommand.html +++ b/doc/MoveCommand.html @@ -16,7 +16,7 @@
-MoveCommand: Contents
  MOVE _key_ _dbindex_
    Return value
    See also +MoveCommand: Contents
  MOVE _key_ _dbindex_
    Return value

MoveCommand

@@ -26,13 +26,13 @@
-

MOVE _key_ _dbindex_

+ #sidebar GenericCommandsSidebar

MOVE _key_ _dbindex_

Move the specified key from the currently selected DB to the specifieddestination DB. Note that this command returns 1 only if the key wassuccessfully moved, and 0 if the target key was already there or if thesource key was not found at all, so it is possible to use MOVE as a lockingprimitive.

Return value

Integer reply, specifically:

 1 if the key was moved
 0 if the key was not moved because already present on the target DB or was not found in the current DB.
-

See also

- + +
diff --git a/doc/MsetCommand.html b/doc/MsetCommand.html index 166f4ac3..5ef51c1c 100644 --- a/doc/MsetCommand.html +++ b/doc/MsetCommand.html @@ -16,7 +16,7 @@

MsetCommand

@@ -26,7 +26,7 @@
- = MSET key1 value1 key2 value2 ... keyN valueN (Redis >= 1.1) = + #sidebar StringCommandsSidebar

MSET _key1_ _value1_ _key2_ _value2_ ... _keyN_ _valueN_ (Redis >

1.1) =

MSETNX _key1_ _value1_ _key2_ _value2_ ... _keyN_ _valueN_ (Redis >

1.1) = Time complexity: O(1) to set every key
Set the the rispective keys to the rispective values. MSET will replace oldvalues with new values, while MSETNX will not perform any operation at alleven if just a single key already exists.
Because of this semantic MSETNX can be used in order to set different keysrepresenting different fields of an unique logic object in a way thatensures that either all the fields or none at all are set.
@@ -34,7 +34,8 @@

MSET Return value

Status code reply Basically +OK as MSET can't fail

MSETNX Return value

Integer reply, specifically:

 1 if the all the keys were set
 0 if no key was set (at least one key already existed)
-

See also

+ +
diff --git a/doc/QuickStart.html b/doc/QuickStart.html index 8d25145e..f4b93361 100644 --- a/doc/QuickStart.html +++ b/doc/QuickStart.html @@ -16,7 +16,7 @@
-QuickStart: Contents
  Quick Start
    Obtain the latest version
    Compile
    Run the server
    Play with the built in client
    Further reading +QuickStart: Contents
    Obtain the latest version
    Compile
    Run the server
    Play with the built in client
    Further reading

QuickStart

@@ -26,7 +26,7 @@
-

Quick Start

This quickstart is a five minutes howto on how to get started with Redis. For more information on Redis check Redis Documentation Index.

Obtain the latest version

The latest stable source distribution of Redis can be obtained at this location as a tarball.

+                    = Quick Start =

This quickstart is a five minutes howto on how to get started with Redis. For more information on Redis check Redis Documentation Index.

Obtain the latest version

The latest stable source distribution of Redis can be obtained at this location as a tarball.

 $ wget http://redis.googlecode.com/files/redis-1.02.tar.gz
 
The unstable source code, with more features but not ready for production, can be downloaded using git:

 $ git clone git://github.com/antirez/redis.git
@@ -57,18 +57,7 @@ firstvalue
 $ ./redis-cli lrange mylist 0 -1
 1. thirdvalue
 2. secondvalue
-
Lists (and Sets too) can be sorted:

-./redis-cli sort mylist alpha
-1. secondvalue
-2. thirdvalue
-
And despite Redis doesn't have integers, you can do some math also:

-$ ./redis-cli get mycounter
-(nil)
-$ ./redis-cli incr mycounter
-1
-./redis-cli incr mycounter
-2
-

Further reading

+

Further reading

diff --git a/doc/QuitCommand.html b/doc/QuitCommand.html index c1508dce..95eb25b6 100644 --- a/doc/QuitCommand.html +++ b/doc/QuitCommand.html @@ -26,7 +26,7 @@
-

Quit

Ask the server to silently close the connection.
+ #sidebar ConnectionHandlingSidebar

Quit

Ask the server to silently close the connection.

Return value

None. The connection is closed as soon as the QUIT command is received.
diff --git a/doc/README.html b/doc/README.html index 38242aa0..2cdeb5c7 100644 --- a/doc/README.html +++ b/doc/README.html @@ -16,7 +16,7 @@

README

@@ -26,32 +26,11 @@
-

Introduction

Redis is a database. To be specific, Redis is a very simple database implementing a dictionary, where every key is associated with a value. For example I can set the key "surname_1992" to the string "Smith". + = Introduction =

Redis is a database. To be specific, Redis is a database implementing a dictionary, where every key is associated with a value. For example I can set the key "surname_1992" to the string "Smith". What makes Redis different from many other key-value stores, is that every single value has a type. The following types are supported:

The type of a value determines what operations (called commands) are available for the value itself. For example you can append elements to a list stored at the key "mylist" using the LPUSH or RPUSH command in O(1). Later you'll be able to get a range of elements with LRANGE or trim the list with LTRIM. Sets are very flexible too, it is possible to add and remove elements from Sets (unsorted collections of strings), and then ask for server-side intersection, union, difference of Sets. Each command is performed through server-side atomic operations. -Please refer to the Command Reference to see the full list of operations associated to these data types.

In other words, you can look at Redis as a data structures server. A Redis user is virtually provided with an interface to Abstract Data Types, saving her from the responsibility to implement concrete data structures and algorithms. Indeed both algorithms and data structures in Redis are properly choosed in order to obtain the best performance.

Redis loads and mantains the whole dataset into memory, but the dataset is persistent, since from time to time Redis writes a dump on disk asynchronously. The dataset is loaded from the dump every time the server is (re)started.

Redis can be configured to save the dataset when a certain number of changes is reached and after a given number of seconds elapses. For example, you can configure Redis to save after 1000 changes and at most 60 seconds since the last save. You can specify any combination for these numbers.

Because data is written asynchronously, when a system crash occurs, the last few queries can get lost (that is acceptable in many applications). Anyway it is possible to make this a non issue, since Redis supports master-slave replication from its early days, being effective even in the case where a few records lost are not acceptable.

Beyond key-value databases

All these features allow to use Redis as the sole DB for your scalable application without the need of any relational database. We wrote a simple Twitter clone in PHP + Redis to show a real world example, the link points to an article explaining the design and internals in very simple words.

What are the differences between Redis and Memcached?

In the following ways:

- -

What are the differences between Redis and Tokyo Cabinet / Tyrant?

Redis and Tokyo Cabinet can be used for the same applications, but actually they are very different beasts. If you read twitter messages of people involved in scalable things both products are reported to work well, but surely there are times where one or the other can be the best choice. Some differences are the followings (I may be biased, make sure to check yourself both the products).

- - - -
-

Does Redis support locking?

No, the idea is to provide atomic primitives in order to make the programmer -able to use redis with locking free algorithms. For example imagine you have -10 computers and one Redis server. You want to count words in a very large text. -This large text is split among the 10 computers, every computer will process -its part and use Redis's INCR command to atomically increment a counter -for every occurrence of the word found.

INCR/DECR are not the only atomic primitives, there are others like PUSH/POP -on lists, POP RANDOM KEY operations, UPDATE and so on. For example you can -use Redis like a Tuple Space (http://en.wikipedia.org/wiki/Tuple_space) in -order to implement distributed algorithms.

(News: locking with key-granularity is now planned)

Multiple databases support

Another synchronization primitive is the support for multiple DBs. By default DB 0 is selected for every new connection, but using the SELECT command it is possible to select a different database. The MOVE operation can move an item from one DB to another atomically. This can be used as a base for locking free algorithms together with the 'RANDOMKEY' commands.

Redis Data Types

Redis supports the following three data types as values:

-Values can be Strings, Lists or Sets. Keys can be a subset of strings not containing newlines ("\n") and spaces (" ").

Note that sometimes strings may hold numeric vaules that must be parsed by -Redis. An example is the INCR command that atomically increments the number -stored at the specified key. In this case Redis is able to handle integers -that can be stored inside a 'long long' type, that is a 64-bit signed integer.

Implementation Details

Strings are implemented as dynamically allocated strings of characters. -Lists are implemented as doubly linked lists with cached length. -Sets are implemented using hash tables that use chaining to resolve collisions.

Redis Tutorial

(note, you can skip this section if you are only interested in "formal" doc.)

Later in this document you can find detailed information about Redis commands, +Please refer to the Command Reference to see the full list of operations associated to these data types.

In other words, you can look at Redis as a data structures server. A Redis user is virtually provided with an interface to Abstract Data Types, saving her from the responsibility to implement concrete data structures and algorithms. Indeed both algorithms and data structures in Redis are properly choosed in order to obtain the best performance.

All data in memory, but saved on disk

Redis loads and mantains the whole dataset into memory, but the dataset is persistent, since at the same time it is saved on disk, so that when the server is restarted data can be loaded back in memory.

There are two kind of persistence supported: the first one is called snapshotting. In this mode Redis, from time to time, writes a dump on disk asynchronously. The dataset is loaded from the dump every time the server is (re)started.

Redis can be configured to save the dataset when a certain number of changes is reached and after a given number of seconds elapses. For example, you can configure Redis to save after 1000 changes and at most 60 seconds since the last save. You can specify any combination for these numbers.

Because data is written asynchronously, when a system crash occurs, the last few queries can get lost (that is acceptable in many applications but not in all). In order to make this a non issue Redis supports another, safer persistence mode, called Append Only File, where every command received altering the dataset (so not a read-only command, but a write command) is written on an append only file ASAP. This commands are replayed when the server is restarted in order to rebuild the dataset in memory.

Redis Append Only File supports a very handy feature: the server is able to safely rebuild the append only file in background in a non-blocking fashion when it gets too long. You can find more details in the Append Only File HOWTO.

Master-Slave replication made trivial

Whatever will be the persistence mode you'll use Redis supports master-slave replications if you want to stay really safe or if you need to scale to huge amounts of reads.

Redis Replication is trivial to setup. So trivial that all you need to do in order to configure a Redis server to be a slave of another one, with automatic synchronization if the link will go down and so forth, is the following config line: slaveof 192.168.1.100 6379. We provide a Replication Howto if you want to know more about this feature.

It's persistent but supports expires

Redis can be used as a memcached on steroids because is as fast as memcached but with a number of features more. Like memcached, Redis also supports setting timeouts to keys so that this key will be automatically removed when a given amount of time passes.

Beyond key-value databases

All these features allow to use Redis as the sole DB for your scalable application without the need of any relational database. We wrote a simple Twitter clone in PHP + Redis to show a real world example, the link points to an article explaining the design and internals in very simple words.

Multiple databases support

Redis supports multiple databases with commands to atomically move keys from one database to the other. By default DB 0 is selected for every new connection, but using the SELECT command it is possible to select a different database. The MOVE operation can move an item from one DB to another atomically. This can be used as a base for locking free algorithms together with the 'RANDOMKEY' commands.

Know more about Redis!

To really get a feeling about what Redis is and how it works please try reading A fifteen minutes introduction to Redis data types.

To know a bit more about how Redis works internally continue reading.

Redis Tutorial

(note, you can skip this section if you are only interested in "formal" doc.)

Later in this document you can find detailed information about Redis commands, the protocol specification, and so on. This kind of documentation is useful but... if you are new to Redis it is also BORING! The Redis protocol is designed so that is both pretty efficient to be parsed by computers, but simple enough @@ -99,8 +78,8 @@ EXISTS foo exist, and ':1' for 'foo', a key that actually exists. Replies starting with the colon character are integer reply.

Ok... now you know the basics, read the REDIS COMMAND REFERENCE section to learn all the commands supported by Redis and the PROTOCOL SPECIFICATION section for more details about the protocol used if you plan to implement one -for a language missing a decent client implementation.

License

Redis is released under the BSD license. See the COPYING file for more information.

Credits

Redis is written and maintained by Salvatore Sanfilippo, Aka 'antirez'.

Enjoy, -antirez +for a language missing a decent client implementation.

License

Redis is released under the BSD license. See the COPYING file for more information.

Credits

Redis is written and maintained by Salvatore Sanfilippo, Aka 'antirez'. +
diff --git a/doc/RandomkeyCommand.html b/doc/RandomkeyCommand.html index 8714f4c6..ac8e8cd4 100644 --- a/doc/RandomkeyCommand.html +++ b/doc/RandomkeyCommand.html @@ -16,7 +16,7 @@
-RandomkeyCommand: Contents
  RANDOMKEY
    Return value
    See also +RandomkeyCommand: Contents
  RANDOMKEY
    Return value

RandomkeyCommand

@@ -26,10 +26,10 @@
-

RANDOMKEY

+ #sidebar GenericCommandsSidebar

RANDOMKEY

Time complexity: O(1)
Return a randomly selected key from the currently selected DB.
-

Return value

Singe line reply, specifically the randomly selected key or an empty string is the database is empty.

See also

- +

Return value

Singe line reply, specifically the randomly selected key or an empty string is the database is empty. +
diff --git a/doc/RenameCommand.html b/doc/RenameCommand.html index 40e85ba2..e5b681cb 100644 --- a/doc/RenameCommand.html +++ b/doc/RenameCommand.html @@ -16,7 +16,7 @@
-RenameCommand: Contents
  RENAME _oldkey_ _newkey_
    Return value
    See also +RenameCommand: Contents
  RENAME _oldkey_ _newkey_
    Return value

RenameCommand

@@ -26,10 +26,10 @@
-

RENAME _oldkey_ _newkey_

+ #sidebar GenericCommandsSidebar

RENAME _oldkey_ _newkey_

Time complexity: O(1)
Atomically renames the key oldkey to newkey. If the source anddestination name are the same an error is returned. If newkeyalready exists it is overwritten.
-

Return value

Status code repy

See also

- +

Return value

Status code repy +
diff --git a/doc/RenamenxCommand.html b/doc/RenamenxCommand.html index d2a742a4..e41d3dae 100644 --- a/doc/RenamenxCommand.html +++ b/doc/RenamenxCommand.html @@ -16,7 +16,7 @@
-RenamenxCommand: Contents
  RENAMENX _oldkey_ _newkey_
    Return value
    See also +RenamenxCommand: Contents
  RENAMENX _oldkey_ _newkey_
    Return value

RenamenxCommand

@@ -26,13 +26,13 @@
-

RENAMENX _oldkey_ _newkey_

+ #sidebar GenericCommandsSidebar

RENAMENX _oldkey_ _newkey_

Time complexity: O(1)
Rename oldkey into newkey but fails if the destination key newkey already exists.

Return value

Integer reply, specifically:

 1 if the key was renamed
 0 if the target key already exist
-

See also

- + +
diff --git a/doc/RoadMap.html b/doc/RoadMap.html index 3100b199..59f35711 100644 --- a/doc/RoadMap.html +++ b/doc/RoadMap.html @@ -16,7 +16,7 @@
-RoadMap: Contents
  Road Map (ROUGH DRAFT)
    TODO
    1.2
    1.1
    1.0 +RoadMap: Contents
  Road Map (ROUGH DRAFT)
    Features added in past versions
    1.1 / 1.2
    0.x / 1.0

RoadMap

@@ -27,8 +27,8 @@
-

Road Map (ROUGH DRAFT)

The up to date, raw Road Map for Redis is part of the source code, you can find it here: http://github.com/antirez/redis/raw/master/TODO

TODO

Add this information:

http://groups.google.com/group/redis-db/browse_thread/thread/95329fcbf7825169/70214fc6cfe01856?lnk=gst&q=roadmap#70214fc6cfe01856

1.2



1.1

-

1.0

+

Road Map (ROUGH DRAFT)

The up to date, raw Road Map for Redis is part of the source code, you can find it here: http://github.com/antirez/redis/raw/master/TODO

Features added in past versions

1.1 / 1.2

+

0.x / 1.0

diff --git a/doc/RpoplpushCommand.html b/doc/RpoplpushCommand.html index 8a54bc4f..dbd82029 100644 --- a/doc/RpoplpushCommand.html +++ b/doc/RpoplpushCommand.html @@ -16,7 +16,7 @@

RpoplpushCommand

@@ -26,15 +26,15 @@
-

RPOPLPUSH _srckey_ _dstkey_ (Redis >

1.1) = + #sidebar ListCommandsSidebar

RPOPLPUSH _srckey_ _dstkey_ (Redis >

1.1) = Time complexity: O(1)
Atomically return and remove the last (tail) element of the srckey list,and push the element as the first (head) element of the dstkey list. Forexample if the source list contains the elements "a","b","c" and thedestination list contains the elements "foo","bar" after an RPOPLPUSH commandthe content of the two lists will be "a","b" and "c","foo","bar".
If the key does not exist or the list is already empty the specialvalue 'nil' is returned. If the srckey and dstkey are the same theoperation is equivalent to removing the last element from the list and pusingit as first element of the list, so it's a "list rotation" command.

Programming patterns: safe queues

Redis lists are often used as queues in order to exchange messages betweendifferent programs. A program can add a message performing an LPUSH operationagainst a Redis list (we call this program a Producer), while another program(that we call Consumer) can process the messages performing an RPOP commandin order to start reading the messages from the oldest.
Unfortunately if a Consumer crashes just after an RPOP operation the messagegets lost. RPOPLPUSH solves this problem since the returned message isadded to another "backup" list. The Consumer can later remove the messagefrom the backup list using the LREM command when the message was correctlyprocessed.
Another process, called Helper, can monitor the "backup" list to check fortimed out entries to repush against the main queue.

Programming patterns: server-side O(N) list traversal

Using RPOPPUSH with the same source and destination key a process canvisit all the elements of an N-elements List in O(N) without to transferthe full list from the server to the client in a single LRANGE operation.Note that a process can traverse the list even while other processesare actively RPUSHing against the list, and still no element will be skipped.
-

Return value

Bulk reply

See also

- +

Return value

Bulk reply +
diff --git a/doc/RpushCommand.html b/doc/RpushCommand.html index 9964e612..18376bc1 100644 --- a/doc/RpushCommand.html +++ b/doc/RpushCommand.html @@ -16,7 +16,7 @@
-RpushCommand: Contents
      RPUSH _key_ _string_
      LPUSH _key_ _string_
    Return value
    See also +RpushCommand: Contents
      RPUSH _key_ _string_
      LPUSH _key_ _string_
    Return value

RpushCommand

@@ -26,11 +26,11 @@
-

RPUSH _key_ _string_

+ #sidebar ListCommandsSidebar

RPUSH _key_ _string_

LPUSH _key_ _string_

Time complexity: O(1)
Add the string value to the head (RPUSH) or tail (LPUSH) of the liststored at key. If the key does not exist an empty list is created just beforethe append operation. If the key exists but is not a List an erroris returned.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/SaddCommand.html b/doc/SaddCommand.html index 3c50a708..699ff22d 100644 --- a/doc/SaddCommand.html +++ b/doc/SaddCommand.html @@ -16,7 +16,7 @@
-SaddCommand: Contents
  SADD _key_ _member_
    Return value
    See also +SaddCommand: Contents
  SADD _key_ _member_
    Return value

SaddCommand

@@ -26,13 +26,13 @@
-

SADD _key_ _member_

+ #sidebar SetCommandsSidebar

SADD _key_ _member_

Time complexity O(1)
Add the specified member to the set value stored at key. If memberis already a member of the set no operation is performed. If keydoes not exist a new set with the specified member as sole member iscrated. If the key exists but does not hold a set value an error isreturned.

Return value

Integer reply, specifically:

 1 if the new element was added
 0 if the element was already a member of the set
-

See also

- + +
diff --git a/doc/SaveCommand.html b/doc/SaveCommand.html index 3c4c3714..4a8c830a 100644 --- a/doc/SaveCommand.html +++ b/doc/SaveCommand.html @@ -16,7 +16,7 @@
-SaveCommand: Contents
      SAVE
    Return value
    See also +SaveCommand: Contents
      SAVE
    Return value

SaveCommand

@@ -26,10 +26,10 @@
-

SAVE

+ #sidebar ControlCommandsSidebar

SAVE

Save the DB on disk. The server hangs while the saving is notcompleted, no connection is served in the meanwhile. An OK codeis returned when the DB was fully stored in disk.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/ScardCommand.html b/doc/ScardCommand.html index ac992fa3..da7b3cbd 100644 --- a/doc/ScardCommand.html +++ b/doc/ScardCommand.html @@ -16,7 +16,7 @@
-ScardCommand: Contents
  SCARD _key_
    Return value
    See also +ScardCommand: Contents
  SCARD _key_
    Return value

ScardCommand

@@ -26,12 +26,12 @@
-

SCARD _key_

+ #sidebar SetCommandsSidebar

SCARD _key_

Time complexity O(1)
Return the set cardinality (number of elements). If the key does notexist 0 is returned, like for empty sets.

Return value

Integer reply, specifically:

 the cardinality (number of elements) of the set as an integer.
-

See also

- + +
diff --git a/doc/SdiffCommand.html b/doc/SdiffCommand.html index 9aaa8220..7aef28b9 100644 --- a/doc/SdiffCommand.html +++ b/doc/SdiffCommand.html @@ -16,7 +16,7 @@
-SdiffCommand: Contents
  SDIFF _key1_ _key2_ ... _keyN_
    Return value
    See also +SdiffCommand: Contents
  SDIFF _key1_ _key2_ ... _keyN_
    Return value

SdiffCommand

@@ -26,7 +26,7 @@
-

SDIFF _key1_ _key2_ ... _keyN_

+ #sidebar SetCommandsSidebar

SDIFF _key1_ _key2_ ... _keyN_

Time complexity O(N) with N being the total number of elements of all the sets
Return the members of a set resulting from the difference between the firstset provided and all the successive sets. Example:
 key1 = x,a,b,c
@@ -34,8 +34,8 @@ key2 = c
 key3 = a,d
 SDIFF key1,key2,key3 => x,b
 
Non existing keys are considered like empty sets.
-

Return value

Multi bulk reply, specifically the list of common elements.

See also

- +

Return value

Multi bulk reply, specifically the list of common elements. +
diff --git a/doc/SdiffstoreCommand.html b/doc/SdiffstoreCommand.html index 818c7fde..93713ac3 100644 --- a/doc/SdiffstoreCommand.html +++ b/doc/SdiffstoreCommand.html @@ -16,7 +16,7 @@
-SdiffstoreCommand: Contents
  SDIFFSTORE _dstkey_ _key1_ _key2_ ... _keyN_
    Return value
    See also +SdiffstoreCommand: Contents
  SDIFFSTORE _dstkey_ _key1_ _key2_ ... _keyN_
    Return value

SdiffstoreCommand

@@ -26,10 +26,10 @@
-

SDIFFSTORE _dstkey_ _key1_ _key2_ ... _keyN_

+ #sidebar SetCommandsSidebar

SDIFFSTORE _dstkey_ _key1_ _key2_ ... _keyN_

Time complexity O(N) where N is the total number of elements in all the provided sets
This commnad works exactly like SDIFF but instead of being returned the resulting set is sotred in dstkey.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/SelectCommand.html b/doc/SelectCommand.html index 11c4b050..e63aa7e4 100644 --- a/doc/SelectCommand.html +++ b/doc/SelectCommand.html @@ -16,7 +16,7 @@
-SelectCommand: Contents
  SELECT _index_
    Return value
    See also +SelectCommand: Contents
  SELECT _index_
    Return value

SelectCommand

@@ -26,10 +26,10 @@
-

SELECT _index_

+ #sidebar GenericCommandsSidebar

SELECT _index_

Select the DB with having the specified zero-based numeric index.For default every new client connection is automatically selectedto DB 0.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/SetCommand.html b/doc/SetCommand.html index 63c51f46..9557be6f 100644 --- a/doc/SetCommand.html +++ b/doc/SetCommand.html @@ -16,7 +16,7 @@
-SetCommand: Contents
  SET _key_ _value_
    Return value
    See also +SetCommand: Contents
  SET _key_ _value_
    Return value

SetCommand

@@ -26,10 +26,10 @@
-

SET _key_ _value_

+ #sidebar StringCommandsSidebar

SET _key_ _value_

Time complexity: O(1)
Set the string value as value of the key.The string can't be longer than 1073741824 bytes (1 GB).
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/SetCommandsSidebar.html b/doc/SetCommandsSidebar.html new file mode 100644 index 00000000..fc612b6c --- /dev/null +++ b/doc/SetCommandsSidebar.html @@ -0,0 +1,36 @@ + + + + + + + +
+ + + +
+
+ +SetCommandsSidebar: Contents +
+ +

SetCommandsSidebar

+ +
+ +
+ + + +
+
+ + + diff --git a/doc/SetnxCommand.html b/doc/SetnxCommand.html index 15a6c0e2..ed4ee167 100644 --- a/doc/SetnxCommand.html +++ b/doc/SetnxCommand.html @@ -16,7 +16,7 @@
-SetnxCommand: Contents
  SETNX _key_ _value_
    Return value
    See also +SetnxCommand: Contents
  SETNX _key_ _value_
    Return value

SetnxCommand

@@ -26,13 +26,13 @@
-

SETNX _key_ _value_

+ #sidebar StringCommandsSidebar

SETNX _key_ _value_

Time complexity: O(1)
SETNX works exactly like SET with the only difference thatif the key already exists no operation is performed.SETNX actually means "SET if Not eXists".

Return value

Integer reply, specifically:

 1 if the key was set
 0 if the key was not set
-

See also

- + +
diff --git a/doc/Sets.html b/doc/Sets.html new file mode 100644 index 00000000..db7e7f9d --- /dev/null +++ b/doc/Sets.html @@ -0,0 +1,37 @@ + + + + + + + +
+ + + +
+
+ +Sets: Contents
  Redis Set Type
  Implementation details +
+ +

Sets

+ +
+ +
+ +
+ #sidebar SetCommandsSidebar

Redis Set Type

Redis Sets are unordered collections of Redis Strings. It's possible to add, remove, and test for existence of members in O(1).

Redis Sets have the desirable property of not allowing repeated members. Adding the same element multiple times will result in a set having a single copy of this element. Practically speaking this means that adding an members does not require a "check if exists then add" operation.

Commands operating on sets try to make a good use of the return value in order to signal the application about previous existence of members. For instance the SADD command will return 1 if the element added was not already a member of the set, otherwise will return 0.

The max number of members in a set is 232-1 (4294967295, more than 4 billion of members per set).

Redis Sets support a wide range of operations, like union, intersection, difference. Intersection is optimized in order to perform the smallest number of lookups. For instance if you try to intersect a 10000 members set with a 2 members set Redis will iterate the 2 members set testing for members existence in the other set, performing 2 lookups instead of 10000.

Implementation details

Redis Sets are implemented using hash tables, so adding, removing and testing for members is O(1) in the average. The hash table will automatically resize when new elements are added or removed into a Set.

The hash table resizing is a blocking operation performed synchronously so working with huge sets (consisting of many millions of elements) care should be taken when mass-inserting a very big amount of elements in a Set while other clients are querying Redis at high speed.

It is possible that in the near future Redis will switch to skip lists (already used in sorted sets) in order to avoid such a problem. + +
+ +
+
+ + + diff --git a/doc/ShutdownCommand.html b/doc/ShutdownCommand.html index ce77ae97..78de2876 100644 --- a/doc/ShutdownCommand.html +++ b/doc/ShutdownCommand.html @@ -16,7 +16,7 @@
-ShutdownCommand: Contents
  SHUTDOWN
    Return value
    See also +ShutdownCommand: Contents
  SHUTDOWN
    Return value

ShutdownCommand

@@ -26,10 +26,10 @@
-

SHUTDOWN

+ #sidebar ControlCommandsSidebar

SHUTDOWN

Stop all the clients, save the DB, then quit the server. This commandsmakes sure that the DB is switched off without the lost of any data.This is not guaranteed if the client uses simply "SAVE" and then"QUIT" because other clients may alter the DB data between the twocommands.
-

Return value

Status code reply on error. On success nothing is returned since the server quits and the connection is closed.

See also

- +

Return value

Status code reply on error. On success nothing is returned since the server quits and the connection is closed. +
diff --git a/doc/SinterCommand.html b/doc/SinterCommand.html index 7a8259b4..528945c5 100644 --- a/doc/SinterCommand.html +++ b/doc/SinterCommand.html @@ -16,7 +16,7 @@
-SinterCommand: Contents
  SINTER _key1_ _key2_ ... _keyN_
    Return value
    See also +SinterCommand: Contents
  SINTER _key1_ _key2_ ... _keyN_
    Return value

SinterCommand

@@ -26,11 +26,11 @@
-

SINTER _key1_ _key2_ ... _keyN_

-Time complexity O(NM) worst case where N is the cardinality of the smallest set and M the number of sets_

Return the members of a set resulting from the intersection of all thesets hold at the specified keys. Like in LRANGE the result is sent tothe client as a multi-bulk reply (see the protocol specification formore information). If just a single key is specified, then this commandproduces the same result as SMEMBERS. Actually SMEMBERS is just syntaxsugar for SINTERSECT.
+ #sidebar SetCommandsSidebar

SINTER _key1_ _key2_ ... _keyN_

+Time complexity O(NM) worst case where N is the cardinality of the smallest set and M the number of sets
Return the members of a set resulting from the intersection of all thesets hold at the specified keys. Like in LRANGE the result is sent tothe client as a multi-bulk reply (see the protocol specification formore information). If just a single key is specified, then this commandproduces the same result as SMEMBERS. Actually SMEMBERS is just syntaxsugar for SINTERSECT.
Non existing keys are considered like empty sets, so if one of the keys ismissing an empty set is returned (since the intersection with an emptyset always is an empty set).
-

Return value

Multi bulk reply, specifically the list of common elements.

See also

-
* SADD* SREM* SISMEMBER* SCARD* SMEMBERS* SINTERSTORE* SUNION* SUNIONSTORE* SMOVE
+

Return value

Multi bulk reply, specifically the list of common elements. +
diff --git a/doc/SinterstoreCommand.html b/doc/SinterstoreCommand.html index 798e7519..61cdbfa3 100644 --- a/doc/SinterstoreCommand.html +++ b/doc/SinterstoreCommand.html @@ -16,7 +16,7 @@
-SinterstoreCommand: Contents
  SINTERSTORE _dstkey_ _key1_ _key2_ ... _keyN_
    Return value
    See also +SinterstoreCommand: Contents
  SINTERSTORE _dstkey_ _key1_ _key2_ ... _keyN_
    Return value

SinterstoreCommand

@@ -26,10 +26,10 @@
-

SINTERSTORE _dstkey_ _key1_ _key2_ ... _keyN_

-Time complexity O(NM) worst case where N is the cardinality of the smallest set and M the number of sets_

This commnad works exactly like SINTER but instead of being returned the resulting set is sotred as _dstkey_.
-

Return value

Status code reply

See also

-
* SADD* SREM* SISMEMBER* SCARD* SMEMBERS* SINTER* SINTERSTORE* SMOVE
+ #sidebar SetCommandsSidebar

SINTERSTORE _dstkey_ _key1_ _key2_ ... _keyN_

+Time complexity O(NM) worst case where N is the cardinality of the smallest set and M the number of sets
This commnad works exactly like SINTER but instead of being returned the resulting set is sotred as dstkey.
+

Return value

Status code reply +
diff --git a/doc/SismemberCommand.html b/doc/SismemberCommand.html index fb900c47..58768ef7 100644 --- a/doc/SismemberCommand.html +++ b/doc/SismemberCommand.html @@ -16,7 +16,7 @@
-SismemberCommand: Contents
  SISMEMBER _key_ _member_
    Return value
    See also +SismemberCommand: Contents
  SISMEMBER _key_ _member_
    Return value

SismemberCommand

@@ -26,13 +26,13 @@
-

SISMEMBER _key_ _member_

+ #sidebar SetCommandsSidebar

SISMEMBER _key_ _member_

Time complexity O(1)
Return 1 if member is a member of the set stored at key, otherwise0 is returned.

Return value

Integer reply, specifically:

 1 if the element is a member of the set
 0 if the element is not a member of the set OR if the key does not exist
-

See also

- + +
diff --git a/doc/SlaveofCommand.html b/doc/SlaveofCommand.html index bbfa8456..8937306c 100644 --- a/doc/SlaveofCommand.html +++ b/doc/SlaveofCommand.html @@ -16,7 +16,7 @@
-SlaveofCommand: Contents
  SLAVEOF _host_ _port_
  SLAVEOF no one
    Return value
    See also +SlaveofCommand: Contents
  SLAVEOF _host_ _port_
  SLAVEOF no one
    Return value

SlaveofCommand

@@ -26,12 +26,12 @@
-

SLAVEOF _host_ _port_

+ #sidebar ControlCommandsSidebar

SLAVEOF _host_ _port_

SLAVEOF no one

The SLAVEOF command can change the replication settings of a slave on the fly.If a Redis server is arleady acting as slave, the command SLAVEOF NO ONEwill turn off the replicaiton turning the Redis server into a MASTER.In the proper form SLAVEOF hostname port will make the server a slave of thespecific server listening at the specified hostname and port.
If a server is already a slave of some master, SLAVEOF hostname port willstop the replication against the old server and start the synchrnonizationagainst the new one discarding the old dataset.
The form SLAVEOF no one will stop replication turning the server into aMASTER but will not discard the replication. So if the old master stop workingit is possible to turn the slave into a master and set the application touse the new master in read/write. Later when the other Redis server will befixed it can be configured in order to work as slave.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/SmembersCommand.html b/doc/SmembersCommand.html index ddee1947..97e30b3b 100644 --- a/doc/SmembersCommand.html +++ b/doc/SmembersCommand.html @@ -16,7 +16,7 @@
-SmembersCommand: Contents
  SMEMBERS _key_
    Return value
    See also +SmembersCommand: Contents
  SMEMBERS _key_
    Return value

SmembersCommand

@@ -26,10 +26,10 @@
-

SMEMBERS _key_

+ #sidebar SetCommandsSidebar

SMEMBERS _key_

Time complexity O(N)
Return all the members (elements) of the set value stored at key. Thisis just syntax glue for SINTERSECT.
-

Return value

Multi bulk reply

See also

- +

Return value

Multi bulk reply +
diff --git a/doc/SmoveCommand.html b/doc/SmoveCommand.html index 5cbde97e..1bdb001f 100644 --- a/doc/SmoveCommand.html +++ b/doc/SmoveCommand.html @@ -16,7 +16,7 @@
-SmoveCommand: Contents
  SMOVE _srckey_ _dstkey_ _member_
    Return value
    See also +SmoveCommand: Contents
  SMOVE _srckey_ _dstkey_ _member_
    Return value

SmoveCommand

@@ -26,15 +26,15 @@
-

SMOVE _srckey_ _dstkey_ _member_

+ #sidebar SetCommandsSidebar

SMOVE _srckey_ _dstkey_ _member_

Time complexity O(1)
Move the specifided member from the set at srckey to the set at dstkey.This operation is atomic, in every given moment the element will appear tobe in the source or destination set for accessing clients.
If the source set does not exist or does not contain the specified elementno operation is performed and zero is returned, otherwise the element isremoved from the source set and added to the destination set. On successone is returned, even if the element was already present in the destinationset.
An error is raised if the source or destination keys contain a non Set value.

Return value

Integer reply, specifically:

 1 if the element was moved
 0 if the element was not found on the first set and no operation was performed
-

See also

- + +
diff --git a/doc/SortCommand.html b/doc/SortCommand.html index 66e40922..8022d53c 100644 --- a/doc/SortCommand.html +++ b/doc/SortCommand.html @@ -16,7 +16,7 @@
-SortCommand: Contents
  SORT _key_ BY _pattern_ LIMIT _start_ _end_ GET _pattern_ ASC|DESC ALPHA
    Return value
    See Also +SortCommand: Contents
    Return value

SortCommand

@@ -26,7 +26,7 @@
-

SORT _key_ BY _pattern_ LIMIT _start_ _end_ GET _pattern_ ASC|DESC ALPHA

+ = SORT key [BY pattern] [LIMIT start count] [GET pattern] [ASC|DESC] [ALPHA] =
Sort the elements contained in the List or Set value at key. By defaultsorting is numeric with elements being compared as double precisionfloating point numbers. This is the simplest form of SORT.
 SORT mylist
@@ -52,8 +52,8 @@ SORT mylist BY weight_* GET object_*
 
Since Redis >= 1.1 it's possible to also GET the list elements itselfusing the special # pattern:
 SORT mylist BY weight_* GET object_* GET #
-

Return value

Multi bulk reply, specifically a list of sorted elements.

See Also

- +

Return value

Multi bulk reply, specifically a list of sorted elements. +
diff --git a/doc/SortedSetCommandsSidebar.html b/doc/SortedSetCommandsSidebar.html new file mode 100644 index 00000000..d52a788b --- /dev/null +++ b/doc/SortedSetCommandsSidebar.html @@ -0,0 +1,36 @@ + + + + + + + +
+ + + +
+
+ +SortedSetCommandsSidebar: Contents +
+ +

SortedSetCommandsSidebar

+ +
+ +
+ +
+ == Sorted Set Commands ==

+
+ +
+
+ + + diff --git a/doc/SortedSets.html b/doc/SortedSets.html new file mode 100644 index 00000000..2a619cf9 --- /dev/null +++ b/doc/SortedSets.html @@ -0,0 +1,37 @@ + + + + + + + +
+ + + +
+
+ +SortedSets: Contents
  Redis Sorted Set Type
  Implementation details +
+ +

SortedSets

+ +
+ +
+ +
+ #sidebar SortedSetCommandsSidebar

Redis Sorted Set Type

Redis Sorted Sets are, similarly to Sets, collections of Redis Strings. The difference is that every member of a Sorted Set hash an associated score that is used in order to take this member in order.

The ZaddCommand command is used to add a new member to a Sorted Set, specifying the score of the element. Calling ZADD against a member already present in the sorted set but using a different score will update the score for the element, moving it to the right position in order to preserve ordering.

It's possible to get ranges of elements from Sorted Sets in a very similar way to what happens with Lists and the LRANGE command using the Sorted Sets ZRANGE command.

It's also possible to get or remove ranges of elements by score using the ZRANGEBYSCORE and ZREMRANGEBYSCORE commands.

The max number of members in a sorted set is 232-1 (4294967295, more than 4 billion of members per set).

Note that while Sorted Sets are already ordered, it is still possible to use the SORT command against sorted sets to get the elements in a different order.

Implementation details

Redis Sets are implemented using a dual-ported data structure containing a skip list and an hash table. When an element is added a map between the element and the score is added to the hash table (so that given the element we get the score in O(1)), and a map between the score and the element is added in the skip list so that elements are taken in order.

Redis uses a special skip list implementation that is doubly linked so that it's possible to traverse the sorted set from tail to head if needed (Check the ZREVRANGE command).

When ZADD is used in order to update the score of an element, Redis retrieve the score of the element using the hash table, so that it's fast to access the element inside the skip list (that's indexed by score) in order to update the position.

Like it happens for Sets the hash table resizing is a blocking operation performed synchronously so working with huge sorted sets (consisting of many millions of elements) care should be taken when mass-inserting a very big amount of elements in a Set while other clients are querying Redis at high speed.

It is possible that in the near future Redis will switch to skip lists even for the element => score map, so every Sorted Set will have two skip lists, one indexed by element and one indexed by score. + +
+ +
+
+ + + diff --git a/doc/SpopCommand.html b/doc/SpopCommand.html new file mode 100644 index 00000000..0a943c65 --- /dev/null +++ b/doc/SpopCommand.html @@ -0,0 +1,40 @@ + + + + + + + +
+ + + +
+
+ +SpopCommand: Contents
  SPOP _key_
    Return value +
+ +

SpopCommand

+ +
+ +
+ +
+ #sidebar SetCommandsSidebar

SPOP _key_

+Time complexity O(1)
Remove a random element from a Set returning it as return value.If the Set is empty or the key does not exist, a nil object is returned.
+
The SRANDMEMBER command does a similar work butthe returned element is not removed from the Set.
+

Return value

Bulk reply + +
+ +
+
+ + + diff --git a/doc/SrandmemberCommand.html b/doc/SrandmemberCommand.html new file mode 100644 index 00000000..43a22387 --- /dev/null +++ b/doc/SrandmemberCommand.html @@ -0,0 +1,40 @@ + + + + + + + +
+ + + +
+
+ +SrandmemberCommand: Contents
  SRANDMEMBER _key_
    Return value +
+ +

SrandmemberCommand

+ +
+ +
+ +
+ #sidebar SetCommandsSidebar

SRANDMEMBER _key_

+Time complexity O(1)
Return a random element from a Set, without removing the element. If the Set is empty or the key does not exist, a nil object is returned.
+
The SPOP command does a similar work but the returned elementis popped (removed) from the Set.
+

Return value

Bulk reply + +
+ +
+
+ + + diff --git a/doc/SremCommand.html b/doc/SremCommand.html index b173f4d2..e5aab23e 100644 --- a/doc/SremCommand.html +++ b/doc/SremCommand.html @@ -16,7 +16,7 @@
-SremCommand: Contents
  SREM _key_ _member_
    Return value
    See also +SremCommand: Contents
  SREM _key_ _member_
    Return value

SremCommand

@@ -26,13 +26,13 @@
-

SREM _key_ _member_

+ #sidebar SetCommandsSidebar

SREM _key_ _member_

Time complexity O(1)
Remove the specified member from the set value stored at key. If_member_ was not a member of the set no operation is performed. If keydoes not hold a set value an error is returned.

Return value

Integer reply, specifically:

 1 if the new element was removed
 0 if the new element was not a member of the set
-

See also

- + +
diff --git a/doc/StringCommandsSidebar.html b/doc/StringCommandsSidebar.html new file mode 100644 index 00000000..af7b5f6b --- /dev/null +++ b/doc/StringCommandsSidebar.html @@ -0,0 +1,36 @@ + + + + + + + +
+ + + +
+
+ +StringCommandsSidebar: Contents +
+ +

StringCommandsSidebar

+ +
+ +
+ +
+ == String Commands ==

+
+ +
+
+ + + diff --git a/doc/Strings.html b/doc/Strings.html new file mode 100644 index 00000000..d05bf928 --- /dev/null +++ b/doc/Strings.html @@ -0,0 +1,37 @@ + + + + + + + +
+ + + +
+
+ +Strings: Contents
  Redis String Type
  Implementation details +
+ +

Strings

+ +
+ +
+ +
+ #sidebar StringCommandsSidebar

Redis String Type

Strings are the most basic Redis kind of values. Redis Strings are binary safe, this means a Redis string can contain any kind of data, for instance a JPEG image or a serialized Ruby object, and so forth.

A String value can be at max 1 Gigabyte in length.

Strings are treated as integer values by the INCR commands family, in this respect the value of an intger is limited to a singed 64 bit value.

Note that the single elements contained in Redis Lists, Sets and Sorted Sets, are Redis Strings.

Implementation details

Strings are implemented using a dynamic strings library called sds.c (simple dynamic strings). This library caches the current length of the string, so to obtain the length of a Redis string is an O(1) operation (but currently there is no such STRLEN command. It will likely be added later).

Redis strings are incapsualted into Redis Objects. Redis Objects use a reference counting memory management system, so a single Redis String can be shared in different places of the dataset. This means that if you happen to use the same strings many times (especially if you have object sharing turned on in the configuration file) Redis will try to use the same string object instead to allocate one new every time.

Starting from version 1.1 Redis is also able to encode in a special way strings that are actually just numbers. Instead to save the string as an array of characters Redis will save the integer value in order to use less memory. With many datasets this can reduce the memory usage of about 30% compared to Redis 1.0. + +
+ +
+
+ + + diff --git a/doc/SunionCommand.html b/doc/SunionCommand.html index 0c4ee4af..7f7ec5b3 100644 --- a/doc/SunionCommand.html +++ b/doc/SunionCommand.html @@ -16,7 +16,7 @@
-SunionCommand: Contents
  SUNION _key1_ _key2_ ... _keyN_
    Return value
    See also +SunionCommand: Contents
  SUNION _key1_ _key2_ ... _keyN_
    Return value

SunionCommand

@@ -26,11 +26,11 @@
-

SUNION _key1_ _key2_ ... _keyN_

+ #sidebar SetCommandsSidebar

SUNION _key1_ _key2_ ... _keyN_

Time complexity O(N) where N is the total number of elements in all the provided sets
Return the members of a set resulting from the union of all thesets hold at the specified keys. Like in LRANGE the result is sent tothe client as a multi-bulk reply (see the protocol specification formore information). If just a single key is specified, then this commandproduces the same result as SMEMBERS.
Non existing keys are considered like empty sets.
-

Return value

Multi bulk reply, specifically the list of common elements.

See also

- +

Return value

Multi bulk reply, specifically the list of common elements. +
diff --git a/doc/SunionstoreCommand.html b/doc/SunionstoreCommand.html index ea1052a6..ea1a59e2 100644 --- a/doc/SunionstoreCommand.html +++ b/doc/SunionstoreCommand.html @@ -16,7 +16,7 @@
-SunionstoreCommand: Contents
  SUNIONSTORE _dstkey_ _key1_ _key2_ ... _keyN_
    Return value
    See also +SunionstoreCommand: Contents
  SUNIONSTORE _dstkey_ _key1_ _key2_ ... _keyN_
    Return value

SunionstoreCommand

@@ -26,10 +26,10 @@
-

SUNIONSTORE _dstkey_ _key1_ _key2_ ... _keyN_

+ #sidebar SetCommandsSidebar

SUNIONSTORE _dstkey_ _key1_ _key2_ ... _keyN_

Time complexity O(N) where N is the total number of elements in all the provided sets
This commnad works exactly like SUNION but instead of being returned the resulting set is sotred as dstkey.
-

Return value

Status code reply

See also

- +

Return value

Status code reply +
diff --git a/doc/TemplateCommand.html b/doc/TemplateCommand.html index 7286836e..274c4966 100644 --- a/doc/TemplateCommand.html +++ b/doc/TemplateCommand.html @@ -26,7 +26,7 @@
- + 

Return value

ReplyTypes

See also

diff --git a/doc/TtlCommand.html b/doc/TtlCommand.html index 94b308c8..53db4ebf 100644 --- a/doc/TtlCommand.html +++ b/doc/TtlCommand.html @@ -16,7 +16,7 @@
-TtlCommand: Contents
  TTL _key_
    Return value
    See also +TtlCommand: Contents
  TTL _key_
    Return value

TtlCommand

@@ -26,9 +26,9 @@
-

TTL _key_

The TTL command returns the remaining time to live in seconds of a key that has an EXPIRE set. This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset. If the Key does not exists or does not have an associated expire, -1 is returned.
-

Return value

Integer reply

See also

- + #sidebar GenericCommandsSidebar

TTL _key_

The TTL command returns the remaining time to live in seconds of a key that has an EXPIRE set. This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset. If the Key does not exists or does not have an associated expire, -1 is returned.
+

Return value

Integer reply +
diff --git a/doc/TypeCommand.html b/doc/TypeCommand.html index 3d30a991..50c5bed9 100644 --- a/doc/TypeCommand.html +++ b/doc/TypeCommand.html @@ -26,7 +26,7 @@
-

TYPE _key_

+ #sidebar GenericCommandsSidebar

TYPE _key_

Time complexity: O(1)
Return the type of the value stored at key in form of astring. The type can be one of "none", "string", "list", "set"."none" is returned if the key does not exist.

Return value

Status code reply, specifically:

 "none" if the key does not exist
diff --git a/doc/ZaddCommand.html b/doc/ZaddCommand.html
index d798eb2b..fa4c8950 100644
--- a/doc/ZaddCommand.html
+++ b/doc/ZaddCommand.html
@@ -16,7 +16,7 @@
             
-ZaddCommand: Contents
  ZADD _key_ _score_ _member_ (Redis >
    Return value
    See also +ZaddCommand: Contents
  ZADD _key_ _score_ _member_ (Redis >
    Return value

ZaddCommand

@@ -26,15 +26,14 @@
-

ZADD _key_ _score_ _member_ (Redis >

1.1) = + #sidebar SortedSetCommandsSidebar

ZADD _key_ _score_ _member_ (Redis >

1.1) = Time complexity O(log(N)) with N being the number of elements in the sorted set
Add the specified member having the specifeid score to the sortedset stored at key. If member is already a member of the sorted setthe score is updated, and the element reinserted in the right position toensure sorting. If key does not exist a new sorted set with the specified_member_ as sole member is crated. If the key exists but does not hold asorted set value an error is returned.
The score value can be the string representation of a double precision floatingpoint number.
-
For an introduction to sorted sets check the Redis sorted sets page.
+
For an introduction to sorted sets check the Introduction to Redis data types page.

Return value

Integer reply, specifically:

 1 if the new element was added
 0 if the element was already a member of the sorted set and the score was updated
-

See also

- +
diff --git a/doc/ZcardCommand.html b/doc/ZcardCommand.html index 6ea758e2..d9a85ef0 100644 --- a/doc/ZcardCommand.html +++ b/doc/ZcardCommand.html @@ -16,7 +16,7 @@
-ZcardCommand: Contents
  ZCARD _key_ (Redis >
    Return value
    See also +ZcardCommand: Contents
  ZCARD _key_ (Redis >
    Return value

ZcardCommand

@@ -26,12 +26,11 @@
-

ZCARD _key_ (Redis >

1.1) = + #sidebar SortedSetCommandsSidebar

ZCARD _key_ (Redis >

1.1) = Time complexity O(1)
Return the sorted set cardinality (number of elements). If the key does notexist 0 is returned, like for empty sorted sets.

Return value

Integer reply, specifically:

 the cardinality (number of elements) of the set as an integer.
-

See also

- +
diff --git a/doc/ZrangeCommand.html b/doc/ZrangeCommand.html index 9402fa49..3a4cfe8f 100644 --- a/doc/ZrangeCommand.html +++ b/doc/ZrangeCommand.html @@ -16,7 +16,7 @@

ZrangeCommand

@@ -26,13 +26,13 @@
-

ZRANGE _key_ _start_ _end_ (Redis >

1.1) = + #sidebar SortedSetCommandsSidebar

ZRANGE _key_ _start_ _end_ (Redis >

1.1) =

ZREVRANGE _key_ _start_ _end_ (Redis >

1.1) = Time complexity: O(log(N))+O(M) (with N being the number of elements in the sorted set and M the number of elements requested)
Return the specified elements of the sorted set at the specifiedkey. The elements are considered sorted from the lowerest to the highestscore when using ZRANGE, and in the reverse order when using ZREVRANGE.Start and end are zero-based indexes. 0 is the first elementof the sorted set (the one with the lowerest score when using ZRANGE), 1the next element by score and so on.
_start_ and end can also be negative numbers indicating offsetsfrom the end of the sorted set. For example -1 is the last element ofthe sorted set, -2 the penultimate element and so on.
Indexes out of range will not produce an error: if start is overthe end of the sorted set, or start > end, an empty list is returned.If end is over the end of the sorted set Redis will threat it just likethe last element of the sorted set.
-

Return value

Multi bulk reply, specifically a list of elements in the specified range.

See also

- +

Return value

Multi bulk reply, specifically a list of elements in the specified range. +
diff --git a/doc/ZrangebyscoreCommand.html b/doc/ZrangebyscoreCommand.html index 5ea3f372..6ffd87b3 100644 --- a/doc/ZrangebyscoreCommand.html +++ b/doc/ZrangebyscoreCommand.html @@ -16,7 +16,7 @@
-ZrangebyscoreCommand: Contents
  ZRANGEBYSCORE _key_ _min_ _max_ (Redis >
    Return value
    See also +ZrangebyscoreCommand: Contents
  ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` (Redis >
    Return value

ZrangebyscoreCommand

@@ -26,10 +26,12 @@
-

ZRANGEBYSCORE _key_ _min_ _max_ (Redis >

1.1) = -Time complexity: O(log(N))+O(M) with N being the number of elements in the sorted set and M the number of elements matching the min and max score
Return the all the elements in the sorted set at key with a score between_min_ and max (including elements with score equal to min or max).
+ #sidebar SortedSetCommandsSidebar

ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` (Redis >

1.1) = +Time complexity: O(log(N))+O(M) with N being the number of elements in the sorted set and M the number of elements returned by the command, so if M is constant (for instance you always ask for the first ten elements with LIMIT) you can consider it O(log(N))
Return the all the elements in the sorted set at key with a score between_min_ and max (including elements with score equal to min or max).
The elements having the same score are returned sorted lexicographically asASCII strings (this follows from a property of Redis sorted sets and does notinvolve further computation).
-

Return value

Multi bulk reply, specifically a list of elements in the specified score range.

See also

+
Using the optional LIMIT it's possible to get only a range of the matchingelements in an SQL-alike way. Note that if offset is large the commandsneeds to traverse the list for offset elements and this adds up to theO(M) figure.
+

Return value

Multi bulk reply, specifically a list of elements in the specified score range. +
diff --git a/doc/ZremCommand.html b/doc/ZremCommand.html index f23f82d0..ecc4b982 100644 --- a/doc/ZremCommand.html +++ b/doc/ZremCommand.html @@ -16,7 +16,7 @@
-ZremCommand: Contents
  ZREM _key_ _member_ (Redis >
    Return value
    See also +ZremCommand: Contents
  ZREM _key_ _member_ (Redis >
    Return value

ZremCommand

@@ -26,12 +26,13 @@
-

ZREM _key_ _member_ (Redis >

1.1) = + #sidebar SortedSetCommandsSidebar

ZREM _key_ _member_ (Redis >

1.1) = Time complexity O(log(N)) with N being the number of elements in the sorted set
Remove the specified member from the sorted set value stored at key. If_member_ was not a member of the set no operation is performed. If keydoes not not hold a set value an error is returned.

Return value

Integer reply, specifically:

 1 if the new element was removed
 0 if the new element was not a member of the set
-

See also

+ +
diff --git a/doc/ZremrangebyscoreCommand.html b/doc/ZremrangebyscoreCommand.html new file mode 100644 index 00000000..304650d1 --- /dev/null +++ b/doc/ZremrangebyscoreCommand.html @@ -0,0 +1,39 @@ + + + + + + + +
+ + + +
+
+ +ZremrangebyscoreCommand: Contents
  ZREMRANGEBYSCORE _key_ _min_ _max_ (Redis >
    Return value +
+ +

ZremrangebyscoreCommand

+ +
+ +
+ +
+ #sidebar SortedSetCommandsSidebar

ZREMRANGEBYSCORE _key_ _min_ _max_ (Redis >

1.1) = +Time complexity: O(log(N))+O(M) with N being the number of elements in the sorted set and M the number of elements removed by the operation
Remove all the elements in the sorted set at key with a score between_min_ and max (including elements with score equal to min or max).
+

Return value

Integer reply, specifically the number of elements removed. + +
+ +
+
+ + + diff --git a/doc/ZscoreCommand.html b/doc/ZscoreCommand.html index b06c7e55..9815f026 100644 --- a/doc/ZscoreCommand.html +++ b/doc/ZscoreCommand.html @@ -16,7 +16,7 @@
-ZscoreCommand: Contents
  ZSCORE _key_ _element_ (Redis >
    Return value
    See also +ZscoreCommand: Contents
  ZSCORE _key_ _element_ (Redis >
    Return value

ZscoreCommand

@@ -26,12 +26,12 @@
-

ZSCORE _key_ _element_ (Redis >

1.1) = + #sidebar SortedSetCommandsSidebar

ZSCORE _key_ _element_ (Redis >

1.1) = Time complexity O(1)
Return the score of the specified element of the sorted set at key.If the specified element does not exist in the sorted set, or the keydoes not exist at all, a special 'nil' value is returned.

Return value

Bulk reply
 the score (a double precision floating point number) represented as string.
-

See also

- + +
diff --git a/doc/index.html b/doc/index.html index a5e1ca71..6daaa2b6 100644 --- a/doc/index.html +++ b/doc/index.html @@ -26,7 +26,7 @@
-

Redis Documentation

Hello! The followings are pointers to different parts of the Redis Documentation.

+

Redis Documentation

Hello! The followings are pointers to different parts of the Redis Documentation.

HOWTOs about selected features

Hacking

-- 2.45.2