Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Installing and Configuring Redis on Linux

Tech 1

Installing Redis from Source on Linux

To install Redis on distributions like CentOS 7 or Ubuntu 18.04:

  1. Download the source archive:

    wget http://download.redis.io/releases/redis-4.0.0.tar.gz
    
  2. Extract the archive:

    tar -xvf redis-4.0.0.tar.gz
    
  3. Compile the source:

    cd redis-4.0.0
    make
    

    If compilation fails due to missing dependencies:

    • Install make: apt install make
    • Install build tools: apt-get install build-essential tcl
    • If encountering jemalloc errrors, compile with:
      make CFLAGS="-DUSE_JEMALLOC=0" install
      
  4. Install binaries:

    make install
    
  5. Start the server:

    redis-server
    
  6. Connect via client in another terminal:

    redis-cli
    

Starting Redis with Custom Ports

Redis can be started on non-default ports:

  • Start server on port 6380:

    redis-server --port 6380
    
  • Connect client to that port:

    redis-cli -p 6380
    

Using Configuration Files

Instead of command-line flags, use a config file for persistent settings.

  1. Prepare a minimal config (redis-6379.conf):

    port 6379
    daemonize yes
    logfile "6379.log"
    dir /usr/local/redis/redis-4.0.0/data
    

    Generate it by stripping comments and blanks from the default redis.conf:

    cat redis.conf | grep -v "^#" | grep -v "^$" > redis-6379.conf
    
  2. Start Redis using the config:

    redis-server redis-6379.conf
    
  3. Verify the process:

    ps -ef | grep redis-server
    

Managing Multiple Redis Instances

Organize configs in a dedicated directory for multi-instance setups.

  1. Create a conf directory and populate it:

    mkdir conf
    mv redis-6379.conf conf/
    cp conf/redis-6379.conf conf/redis-6380.conf
    
  2. Edit conf/redis-6380.conf to change:

    port 6380
    logfile "6380.log"
    
  3. Launch both instances:

    redis-server conf/redis-6379.conf
    redis-server conf/redis-6380.conf
    
  4. Test connectivity:

    redis-cli -p 6379
    # Set and get key in instance 6379
    
    redis-cli -p 6380
    # Set and get key in instance 6380
    

Stopping Redis Instances

To stop a running instance:

  1. Find its PID:

    ps -ef | grep redis-server
    
  2. Terminate it:

    kill -9 <PID>
    

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.