I work on multiple environments. Each environment has purpose and i have to update code from an environment to another, and database from another one to second.
Ex :
Dev branch code merged to Staging branch (so staging has last code features)
Master branch database to Staging branch database (so Staging has last datas)

But Redis keep all datas, and no options allow me to flush them.

So module should add a feature to flush redis cache database for maintenance stuff.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

GoZ’s picture

Status: Active » Needs review
FileSize
2.71 KB

Here is a patch to add flushDB features and drush command.

I add two ways to flush DB.

First : redis-flush use flushDB which flush ALL current database. So if you have many site on one database, all datas will be lost.
Second : redis-flush-safe use flushDBSafe which delete all rows from current site (thanks to prefix). Take more time but safer.

pounard’s picture

Status: Needs review » Needs work

That's a good start, thank you very mucgh! This is a useful Drush command.

If you consider that you don't need Drupal at all nor the cache API to run commands on Redis using the Redis_Client class directly, you could just write your Drush commands this way:

Redis_Client::getClient()->flushdb();

I think this should work fine with both Predis and PhpRedis, and this won't need more than DRUPAL_BOOTSTRAP_CONFIGURATION bootstrap level to run flawlessly.

It's a saner first step than modifying the cache backend object right now.

GoZ’s picture

FileSize
1.52 KB

New patch to Just call class on drush command.

GoZ’s picture

Status: Needs work » Needs review
pounard’s picture

Nice this seems perfect, I will test it as soon as I can then commit it.

pounard’s picture

@GoZ in the 3.x release flush is safe and faster, thanks to eval or the lazy flush-on-read mode, is this patch still useful for you?

pounard’s picture

I just released the 7.x-2.13 that brings the EVAL speedup to the 2.x branch. Now, it's your turn to have some attention, you're the next one in the list, will be available within the week!

pounard’s picture

Status: Needs review » Fixed

I will probably do another release soon enough.

  • Pierre.R committed 2fdf7b3 on 7.x-2.x authored by GoZ
    Issue #2402567 by GoZ: Add drush command to flush DB
    
pounard’s picture

Version: 7.x-2.12 » 7.x-3.x-dev
Status: Fixed » Active

Not fixed, I need to port this in the 3.x branch.

pounard’s picture

@GoZ latest 2.x release now features the drush command.

joelpittet’s picture

Status: Active » Needs review
FileSize
1.57 KB
1.76 KB

Here's a patch for 3.x based off the committed version but the interdiff is against #3

interdruper’s picture

Status: Needs review » Needs work

It seems that FLUSH_ALL constant is not defined in the 7.x-3.x branch:

PHP Fatal error: Undefined class constant 'FLUSH_ALL' in redis/redis.drush.inc on line 43

Jim Kirkpatrick’s picture

@pounard Is the 3.x version of Redis_Client::FLUSH_ALL now Redis_Cache::FLUSH_NORMAL? If not, what is? Thanks.

Jim Kirkpatrick’s picture

Status: Needs work » Needs review
amontero’s picture

Status: Needs review » Needs work

+1 to flush commands from Drush.

None of both commands feature error handling. Both will print a success message, even if something goes wrong.
Not sure if called methods do return some useful value.

geek-merlin’s picture

Related issues: +#2853835: drush redis-cli
pounard’s picture

Flush command is problematic because it doesn't care about key namespaces or anything else, it's pretty much like a DROP DATABASE in SQL, it just deletes everything, even if it doesn't belong to the current site. That's why, even today, few years after, I still didn't implemented it. It's a dangerous command, and sysadmin can do what they want using redis-cli, where drush should not take this responsability.

It's worse as soon as you do sharding, and have proxy assisted sharding, a whole lot of other scenarios: flush is just not possible. I'd prefer not to provide this methods when in 2 out of 3 possible usage scenarios it will not work.

amontero’s picture

+1 to @pounard's concern.
If command is added, it should include a big confirmation prompt warning of the drop-like effects. It can also drop currently held locks, if using Redis as lock backend.
FYI: Now there is a, safer, less aggressive way of deleteing all keys (via deleteByPrefix('*') method) in Redis using the patch submitted at #2851625: New feature: option to use SCAN command instead of KEYS on cache wildcard deletions.