Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to clean redis all db? #2

Open
takanamito opened this issue Mar 9, 2018 · 2 comments
Open

How to clean redis all db? #2

takanamito opened this issue Mar 9, 2018 · 2 comments

Comments

@takanamito
Copy link

It looks like database_cleaner[:redis] clean only a selected db.
https://github.com/DatabaseCleaner/database_cleaner/blob/f052d64d3be9351a98a99e932a59be528ccc561c/lib/database_cleaner/redis/truncation.rb#L10-L23

In my case, application uses multiple redis db.
So I'd prefer to use not redis.flushdb but redis.flushall.

Can I use redis.flushall in database_cleaner?

@etagwerker
Copy link
Member

@takanamito Have you tried configuring multiple connections with DatabaseCleaner? You can see a couple of examples over here: https://github.com/DatabaseCleaner/database_cleaner#how-to-use-with-multiple-orms

@takanamito
Copy link
Author

takanamito commented May 14, 2018

@etagwerker Thank you for your advice.

I tried multiple connections config.
But it's not good for me.

I uses multiple redis db in rspec.

Hosts:

redis://localhost:6379/1
redis://localhost:6379/2
redis://localhost:6379/3

And DatabaseCleaner config

config.after(:example) do
  (1..3).each do |db|
    DatabaseCleaner[:redis].db = "redis://localhost:6379/#{db}"
    DatabaseCleaner.clean
  end
  binding.pry
end


# execution log
# @db: "redis://localhost:6379/3"
# but @connection is "redis://localhost:6379/1"
[1] pry(#<RSpec::ExampleGroups::MySpec>)> DatabaseCleaner[:redis]
=> #<DatabaseCleaner::Base:0x00563f8f436730
 @db="redis://localhost:6379/3",
 @orm=:redis,
 @strategy=
  #<DatabaseCleaner::Redis::Truncation:0x00563f8f4247d8
   @cache_tables=true,
   @connection=#<Redis client v3.3.5 for redis://localhost:6379/1>,
   @db="redis://localhost:6379/3",
   @only=nil,
   @pre_count=nil,
   @reset_ids=nil,
   @tables_to_exclude=[]>>

DatabaseCleaner::Redis#connection methods has @connection variable.
https://github.com/DatabaseCleaner/database_cleaner/blob/master/lib/database_cleaner/redis/base.rb#L24-L34

I think that,
The instance variable is called, when Database.clean.
And always uses first connection that point to redis://localhost:6379/1.


If it's ok, I would like to send a patch adding options redis.flushall.

@botandrose botandrose transferred this issue from DatabaseCleaner/database_cleaner Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants