59

I have some information stored in my RedisToGo instance in Heroku and I want to wipe it so the Redis store is clean. Any idea how to do this?

kidcapital
  • 5,064
  • 9
  • 46
  • 68

12 Answers12

106

You can do this with redis-cli.

RedisToGo gives you a url in the form:

redis://redistogo:d20739cffb0c0a6fff719acc2728c236@catfish.redistogo.com:9402

So this command will empty your db:

redis-cli -h catfish.redistogo.com -p 9402 -a d20739cffb0c0a6fff719acc2728c236 flushall
ty.
  • 10,924
  • 9
  • 52
  • 71
  • 1
    This gives me `(error) NOAUTH Authentication required.`. What is that about? –  Apr 26 '15 at 04:04
  • 1
    @torazaburo That error occurs when you've entered bad credentials. – ty. Sep 02 '15 at 09:11
  • This no longer works. You get a NOAUTH error. There may be a missing step, but the steps above will just yield an error. – Jesse Farmer Sep 21 '18 at 04:18
  • @JesseFarmer I was just able to run this command successfully. Received "OK" response. You might want to double check your credentials. – ty. Sep 22 '18 at 08:11
  • @ty, it responds with OK, but it seems like it doesn't actually clear it. So far I wasn't able to find a way to clear rediscloud redis without accessing rails console. – AndreiMotinga Sep 29 '18 at 18:47
  • For anyone reading this answer, you can simply do `redis-cli -u redis://...` with the URL – Tallboy May 08 '22 at 02:54
54

You can install the heroku-redis-cli plugin

Installation

Requirements:

  • The heroku gem — gem install heroku

  • A local installation of redis (or at least the redis-cli utility) — apt-get install redis-server

To install:

  • heroku plugins:install https://github.com/rapportive-oss/heroku-redis-cli.git

Usage

  • heroku redis:info — get run-time statistics from your redis.

  • heroku redis:monitor — monitor commands being sent to your redis in real time.

  • heroku redis:cli — execute custom commands against redis.

Then you could simply do:

$ heroku redis:cli
$ flushall

Steps taken from readme file on the github repo: https://github.com/rapportive-oss/heroku-redis-cli

esbanarango
  • 1,634
  • 15
  • 17
36

To wipe your redis on heroku there are a couple of ways. One of the simplest is probably connecting to the heroku console and clearing it from there. Commands are (for cedar stack):

heroku run console
REDIS.flushall

And that's it :-)

25

You can do this with the heroku console:

$ heroku redis:cli -a my_app --confirm my_app
$ FLUSHALL

Source: https://menubar.io/heroku-redis-flushall

nmu
  • 1,442
  • 2
  • 20
  • 40
13

You can destroy and recreate the entire Redis datastore for your app by doing:

heroku addons:remove redistogo
heroku addons:add redistogo
James Ward
  • 29,283
  • 9
  • 49
  • 85
10

In order to empty the store, you can run the flushall command: http://redis.io/commands/flushall

So, simply something like:

$redis.flushall

if you're doing it with Ruby or similar.

Neil Middleton
  • 22,105
  • 18
  • 80
  • 134
  • 2
    It depends on what you're using to be honest, if it's something like Rails you can run it via the Rails console (`heroku run console`) - however, it's very dependant on what tools you're using. – Neil Middleton Feb 05 '12 at 13:36
9

Get a python shell on heroku by doing the following CLI:

heroku run python

Then in that shell type

import os
import redis
redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost')
r = redis.from_url(redis_url) 
r.flushdb()
Javaaaa
  • 3,788
  • 7
  • 43
  • 54
3

heroku run rails c

$redis.flushall

jamesdlivesinatree
  • 1,016
  • 3
  • 11
  • 36
3

I'm using Ruby on Rails on Heroku and tried this, it worked (After heroku run rails console)

> $redis = Redis.new url: ENV['REDISCLOUD_URL']
> $redis.flushall
=> "OK"
kangkyu
  • 5,252
  • 3
  • 34
  • 36
2

This can be done in one convenient one-liner, even for non-ruby apps:

echo " FLUSHALL\r\n QUIT" | heroku redis:cli -a MY_APP --confirm MY_APP

Replace MY_APP with the name of your app.


Note: This assumes that you have Heroku CLI installed.

Andreas
  • 958
  • 12
  • 14
2

You can use this https://github.com/rapportive-oss/heroku-redis-cli to connect to the Redis instance you are using, Heroku update broke it some time ago but there is a fix https://github.com/johnbeynon/heroku-redis-cli. Then just do flushdb

Dmytro Yashkir
  • 1,225
  • 12
  • 12
1

If you're looking for a one-liner (and happen to be using Rails), you can do

heroku run rails runner 'REDIS.flushall'

rather than connecting first (with console) then manually entering the flushall command.

Ollie Bennett
  • 4,424
  • 1
  • 19
  • 26