82

After writing some data to a redis server, I could read the data from a client. However, how can I find the data directory on the file system?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
bafla
  • 1,029
  • 1
  • 10
  • 14

3 Answers3

142

Quickest method: use redis-cli.

redis-cli config get dir

If you have authentication configured, you will need to pass that in using -a password Replacing "password" with your password.

The Real Bill
  • 14,884
  • 8
  • 37
  • 39
  • 17
    This didn't work for me, it returned a completely wrong directory. I found my config at `/usr/local/etc/redis.conf`. – gdvalderrama Jun 11 '18 at 12:04
  • 4
    It gave you the config for the instance you connected to. If not, file a bug. – The Real Bill Jul 20 '18 at 04:25
  • 2
    this command will return the application directory location based on the redis.conf file or default config (if you don't have one) not the config file location – Salman El Farisi Oct 20 '20 at 07:43
  • This outputs two directories; which is correct? – DylanYoung Dec 08 '21 at 20:22
  • Is there a response that could be consistent when running Docker? For instance when running Mongo I map volumes like so: "'./.mongo:/data/db'", pretty useful to control the location of data during local dev. I am trying to find an equivalent for Redis. – Eric Burel Aug 17 '23 at 13:49
38

Find your Redis configuration directory, probably /etc/redis. Then look in the config file called redis.conf and find the line that starts dir.

It will look similar to this:

dir /etc/redis/database

This will do the job slowly but surely if you can't be bothered to look :-)

sudo find / -name "redis.conf" -exec grep "^dir" {} \; 2> /dev/null
dir /etc/redis

or if you want the config filename as well:

sudo find / -name "redis.conf" -exec grep -H "^dir" {} \; 2> /dev/null
/private/etc/redis/redis.conf:dir /etc/redis

Other possibilities you can check are whether Redis was started with a custom config file as its first parameter like this:

redis-server /path/to.custom/config-file

or with the dir option set on the commandline like this:

redis-server dir /path/to/data

Use

ps -aef | grep redis

to look for these options.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
3

Because Redis config file can be located in several possible places (depending on the system or container, such as /opt/redis/ in my case), a general solution to find the currently configured location of the RDB file (as set using dir in redis.conf - if config file is used at all*) is:

$ cat $(cd / && find | grep redis.conf) | grep dir

*Note that true to its simplicity Redis by default ships without any config files (using built-in configuration which depends on the version, see docs), and this is indeed the case for the official redis:latest container.

mirekphd
  • 4,799
  • 3
  • 38
  • 59