Running redis-server without any options is good for test, but not enough for production environment. To customize it, you need to build configuration file.
The following options are from version 4.x. And you can refer full documentation here.
Basic options for standalone mode
- bind some_ip # If you do not set bind ip, then Redis listens for all interfaces
- protected-mode no # In protected mode, only clients in the same host can connect
- port 6379 # Default port is 6379
- daemonize yes # If set yes, Redis runs in background mode. Default is no
- pidfile /some/path/to/pidfile
- logfile “/some/path/to/logfile” # If value is “”, log is sent to standard out. The value must be set as absolute path
- maxmemory <bytes> # If this option is not set, Redis can overflow server memory
- maxmemory-policy allkeys-lru # If maxmemory is set, this policy is applied when max memory is reached. Default is “noeviction”, which means “Don’t evict anything, just return an error on write operations” I prefer “allkeys-lru” for use case for cache
Redis supports persistence with 2 options – 1) RBB (snapshot) 2) AOF.
Both methods are not exclusive. You can check pros and cons for each option => Detailed explanation
- save <seconds> <changes> # Option for RDB. If changes occur during seconds, snapshot is executed. If multiple save are declared, in any matching condition, snaphot is executed
- dir some_path # Working directory for RDB and AOF
- dbfilename dumpFile.rdb # RDB snapshot file name which is generated at working directory
- appendonly yes # If set yes, AOF is enabled. Default is no
- appendfilename “appendonly.aof” # AOF file name. It is generated at working directory
- requirepass some_password # If password is set, clients must issue AUTH <password> command, or -a option for redis-cli. Redis recommends very long password
Running with config file
After generating config file, you can run Redis with it as follows.
# ./redis-server path/to/config/redis.conf