Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute redis FLUSHALL command in rails application

I want to FLUSHALL redis every time the Rails server starts.

How can I do this?

Thanks in Advance.

P.S: I am new to rails, so excuse me if the question is very easy.

like image 557
Tamer Shlash Avatar asked Jul 10 '12 19:07

Tamer Shlash


People also ask

What is Flushall in Redis?

FLUSHALL [ ASYNC | SYNC]Delete all the keys of all the existing databases, not just the currently selected one. This command never fails. By default, FLUSHALL will synchronously flush all the databases.

How do I run Redis commands?

To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command. In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.

How do I reset Redis cache?

To clear data of a DCS Redis 4.0 or 5.0 instance, you can run the FLUSHDB or FLUSHALL command in redis-cli, use the data clearing function on the DCS console, or run the FLUSHDB command on Web CLI. To clear data of a Redis Cluster instance, run the FLUSHDB or FLUSHALL command on every shard of the instance.

How do I clear a key in Redis?

Redis Commands There are two major commands to delete the keys present in Redis: FLUSHDB and FLUSHALL. We can use the Redis CLI to execute these commands. The FLUSHDB command deletes the keys in a database. And the FLUSHALL command deletes all keys in all databases.


1 Answers

port = 10000
$redis = Redis.new(:port => port)
$redis.flushall

http://fhwang.net/2010/09/23/Testing-Rails-against-a-running-Redis-instance-and-doing-it-with-Hydra-to-boot

To run that on start up check https://stackoverflow.com/a/7091991/643500

like image 182
Sully Avatar answered Oct 22 '22 16:10

Sully