10

I want to write application in python which uses redis. I googled but I could not find any results for my question. Usually, I do this:

import redis

rs = redis.Redis('localhost')

then do all gets and sets. But can I in redis do something like this:

rs1 = redis.Redis('app1')
rs2 = redis.Redis('app2')

I mean, I want to use two or more instances, each of which stores different things (for example rs1 for urls, rs2 for headers, etc...). And also I want to know how to delete all keys (for example in rs1 delete all records). Any good tutorial, resource? Note: I need to use redis because I need to preform fast check and store, like url-seen for crawler.

1
  • 1
    Read redis.io. It has comprehensive documentation for all redis commands. Commented May 30, 2012 at 11:10

1 Answer 1

22

As showed in the getting started section of the docs redis.Redis and redis.StrictRedis both take an integer db argument as a constructor parameter. That will get you an effectively silo'ed instance.

You could do something like the following:

rs1 = redis.Redis(host="localhost", db=0)
rs2 = redis.Redis(host="localhost", db=1)

flushdb() will clear all the keys for the database you are connected to, while flushall() will clear all the keys for every database.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, flushall will clear all keys in all DBS. Flushdb is for flushing the db you are connected to. The flushall demonstrates that the DBS are not siloed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.