Permalink
Browse files

rewrote trivial recipe into something more meaningful

  • Loading branch information...
1 parent 6dd968b commit 0cb7ea48f7072ac41b1030a2660bd43e20245042 @tlossen tlossen committed May 10, 2010
@@ -1,8 +0,0 @@
----
-title: Empty the Database
-credit:
- - Tim Lossen
-tags:
- - basic
- - FLUSHALL
- - FLUSHDB
@@ -1,12 +0,0 @@
-"""
-Empty the database - example
-Language: Python
-Client : redis-py
-"""
-
-#Instantiate the Redis object
-r = redis.Redis()
-
-#Delete all keys and values
-r.flushdb()
-
@@ -1,16 +0,0 @@
-### Problem
-
-You want to delete all keys (and their associated values) that have been stored in Redis.
-
-### Solution
-
-Use Redis' FLUSHALL command.
-
- $redis-cli flushall
- OK
-
-### Discussion
-
-### See Also
-
-
@@ -0,0 +1,9 @@
+---
+title: Working with Multiple Databases
+credit:
+ - Tim Lossen
+tags:
+ - basic
+ - SELECT
+ - DBSIZE
+ - FLUSHDB
@@ -0,0 +1,51 @@
+### Problem
+
+You want to keep different kinds of data — belonging to different
+applications, for example — separate from each other, but store them
+all in the same Redis instance.
+
+
+### Solution
+
+Use different Redis databases for different kinds of data.
+In Redis, databases are identified by an integer index, not by a database name.
+By default, a client is connected to database 0.
+With the `SELECT` command you can switch to a different database:
+
+ redis> select 3
+ OK
+
+All subsequent commands will then use database 3, until you issue another `SELECT`.
+
+
+### Discussion
+
+Each Redis database has its own keyspace.
+By using different databases for your 'staging' and 'production' data,
+for example, you don't have to worry about key clashes between the two.
+
+There is also a command to drop all the data in a single database:
+
+ redis> flushdb
+ OK
+
+This comes in very handy if you want to reset your 'staging' database.
+
+If you want to get rid of all the data in a Redis instance, you can use
+`FLUSHALL` instead. But be careful, there is no security check, and this
+command is guaranteed to never fail.
+
+The number of databases which is available can be configured in `redis.conf` —
+by default, it is set to 16. Simply set it to a higher number if you need
+more:
+
+ databases 42
+
+Unfortunately, Redis does not provide a way to associate names with the
+different databases, so you will have to keep track of what data goes where
+yourself.
+
+
+### See Also
+
+

0 comments on commit 0cb7ea4

Please sign in to comment.