Connect To Redis From A Different Machine

IMPORTANT: Making this application’s network ports public is a significant security risk. You are strongly advised to only allow access to those ports from trusted networks. If, for development purposes, you need to access from outside of a trusted network, please do not allow access to those ports via a public IP address. Instead, use a secure channel such as a VPN or an SSH tunnel.

Open Port ( if Needed)

sudo ufw allow 7001

[ Verify it: ]

sudo ufw status verbose

redis-cli -h XXX.XXX.XXX.XXX -p YYYY

xxx.xxx.xxx.xxx is the IP address and yyyy is the port

EXAMPLE from my dev environment

redis-cli -h 10.144.62.3 -p 7001
[ -c for cluster ]
redis-cli -h 10.144.62.3 -p 7001 -c  

Replace the YOURPASSWORD placeholder with the value of your password:

redis-cli -h SERVER-IP -a YOURPASSWORD

Note: Disable Protected Mode and Bind Address 0.0.0.0 from node.conf file

exit

Move Redis database from one server to another (Migration)

Redis dump file is 100% backwards compatible. An older dump file format will always work with a newer version of Redis.

First, create a dump on server A.

A$ redis-cli
127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/var/lib/redis/"
127.0.0.1:6379> SAVE
OK

This ensures dump.rdb is completely up-to-date, and shows us where it is stored (/var/lib/redis/dump.rdb in this case). dump.rdb is also periodically written to disk automatically.

Next, copy it to server B:

A$ scp /var/lib/redis/dump.rdb myuser@B:/tmp/dump.rdb

Stop the Redis server on B, copy dump.rdb (ensuring permissions are the same as before), then start.

B$ sudo service redis-server stop
B$ sudo cp /tmp/dump.rdb /var/lib/redis/dump.rdb
B$ sudo chown redis: /var/lib/redis/dump.rdb
B$ sudo service redis-server start

The version of Redis on B must be greater or equal than that of A

Note: Simple (python) Script you can use : https://github.com/arifmarias/redismigration

Upgrade Redis

First, find the location of your installed redis-server instance before updating. In my case, it was in /usr/local/bin/, but it might also be in /usr/bin/. If it’s not here, you can type which redis-server to find the location.

Next, download the redis tar file from https://redis.io/download, then install it from the directory it downloaded to:

cd Downloads
wget http://download.redis.io/releases/redis-X.Y.Z.tar.gztar xzf redis-X.Y.Z.tar.gz
cd redis-X.Y.Z
make
make test

Next, we’ll move the new installed redis to the location where the current instance is running:

sudo mv src/redis-server /usr/local/bin
sudo mv src/redis-cli /usr/local/bin

After copy content you need restart redis-server:

sudo /etc/init.d/redis-server restart

To validate the version of redis-server and redis-cli run:

redis-cli -v #redis-cli version
redis-cli INFO #redis-server version

Now you should be ready to use redis-server and redis-cli in the new version.

Setting the Log Location in redis.conf

The Redis log location is specified in Redis’s configuration file, redis.conf, often located at /etc/redis/redis.conf.

Open that file for editing:

sudo nano /etc/redis/redis.conf

Locate the logfile line:/etc/redis/redis.conf

logfile /var/log/redis/redis-server.log

Note the location of the log files. You can edit this file path if you want to rename the log file or change its location.

If your logs aren’t in either of those locations, you can conduct a more general search using find in the /var/logs directory:

find /var/log/* -name *redis*

Or, search your entire system. This might take a while if you have a lot of files. It will turn up a few permission warnings, which is normal, although we’re avoiding the worst of them in /proc and /sys with the two -prune flags. It will also turn up every file with redis in the name, which includes installation files:

find / -path /sys -prune -o -path /proc -prune -o -name *redis*

Configuring a Redis Password ( Authentication )

Configuring a Redis password enables one of its two built-in security features — the auth command, which requires clients to authenticate to access the database. The password is configured directly in Redis’s configuration file, /etc/redis/redis.conf, so open that file again with your preferred editor:

sudo nano /etc/redis/redis.conf

Scroll to the SECURITY section and look for a commented directive that reads:/etc/redis/redis.conf

# requirepass foobared

Uncomment it by removing the #, and change foobared to a secure password.

After setting the password, save and close the file, then restart Redis

To test that the password works, access the Redis command line:

redis-cli

The following shows a sequence of commands used to test whether the Redis password works. The first command tries to set a key to a value before authentication:

set key1 10

That won’t work because you didn’t authenticate, so Redis returns an error:

Output(error) NOAUTH Authentication required.

The next command authenticates with the password specified in the Redis configuration file:

auth your_redis_password

Redis acknowledges:

Output
OK

After that, running the previous command again will succeed:

set key1 10
Output
OK