Alibaba cloud deployment 3.redis


Download and compile

tar xzf redis-4.0.2.tar.gz
cd redis-4.0.2

Startup service

Start redis in the background

cd redis-4.0.2/
src/redis-server &

Query redis process

ps -ef | grep redis

You can see that redis has been started.

root     19141 19065  0 12:50 pts/1    00:00:03 ./src/redis-server
root     19238 19196  0 14:00 pts/0    00:00:00 grep --color=auto redis

End process

kill -9 pid

Preliminary test

Start redis client

cd redis-4.0.2/
src/redis-cli> set test 1
OK> get test

redis installation succeeded.

Configure server remote connections

The default configuration can only be local access. We modify the redis-4.0.2/redis.conf configuration file.


Modified to



You need to add security group rules and open port 6379 on the server firewall.

Set remote connection password

Protection mode is on by default

protected-mode yes

At this time, you need to set a password to connect to redis remotely. The password setting is very simple. Just fill in your password in the required pass field.

requirepass your password

After configuration, start your redis in the background.

./redis-server /etc/redis/redis.conf

node client connection

I use the redis package on npm. At this time, you can connect to redis on the server remotely according to the previous configuration. Combination Developing documents , you can actually develop it.

const redis = require('redis');
const config = require('../config');

const logger = require('log4js').getLogger('app');

class RedisClient {
  constructor() {
    if (!RedisClient.instance) {
      this.client = redis.createClient({
        port: config.redis.port,
        password: config.redis.password,

      const client = this.client;
      RedisClient.instance = client;
      client.on("error", (err) => {
        logger.error('redis connect err: %s', err.toString());
      client.on("connect", () => {'redis connect success');

module.exports = new RedisClient().client;

Keywords: Javascript Redis firewall npm

Added by rocco2004 on Wed, 23 Oct 2019 20:00:19 +0300