Skip to main content

Redis

Install

# Install ubuntu 20.04=>5.x / 18.04
sudo apt-get install redis-server

# Manual install
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make

# Check status
sudo systemctl status redis-server

# Restart
sudo service redis-server restart

Config

sudo vi /etc/redis/redis.conf
  • port: The port connect to Redis Server. Default is 6379.
  • bind: The network interface for Redis Server. Default is 127.0.0.1. bind 127.0.0.1: not allow other ip. Example: bind 192.168.50.85
  • requirepass: The password for connect to Redis Server.
  • protected-mode: 'no' will open the remote access.

Test

redis-cli

# Authenticate
auth password
Redis> ping
PONG
redis> set foo bar
OK
redis> get foo
"bar"

Remote Connect

redis-cli -h {redis_host} -p {redis_port}
keys *

keys apple*

type "eleccoin:blocksPending"

SMEMBERS "eleccoin:blocksPending"

Multi instance

cd /etc/redis/
cp redis.conf redis_6389.conf
vi redis_6389.conf
# port 6489
# daemonize yes
# logfile /var/log/redis/redis-server-6389.log
# dir /var/lib/redis_6389
# pidfile /var/run/redis/redis-server-6389.pid

mkdir /var/lib/redis_6389

# Start command
redis-server /etc/redis/redis_6389.conf

cd /usr/lib/systemd/system/
vi redis-6389.service

Code in redis-6389.service

[Unit]
Description=redis-server on 6389
After=syslog.target
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis/redis-server-6389.pid
ExecStart=/usr/bin/redis-server /etc/redis/redis_6389.conf
ExecStop=/usr/bin/redis-cli shutdown
# Place temp files in a secure directory, not /tmp
PrivateTmp=true

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start redis-6389.service
sudo systemctl enable redis-6389.service