Redis Server Support for ISPConfig

Discussion in 'Feature Requests' started by traezi, Mar 17, 2025.

  1. traezi

    traezi New Member

    I would like to request the integration of Redis Server support in ISPConfig with the following features:
    1. Multiple Instance Support
      • The ability to create multiple Redis instances.
      • Each instance runs on an incremented port.
    2. Predefined Optimization Modes
      • Cache-Optimized: Suitable for standard caching purposes.
      • Full Page Cache-Optimized: Ideal for full-page caching solutions.
      • Session-Optimized: Designed for handling session storage.
      • Custom Configuration: Allows individual customers to configure their instance with standard values and additional custom settings.
    3. Memory Allocation per Instance
      • Ability to set the allocated memory per Redis instance.
    4. Max Memory Policies Selection
      • Support for the following eviction policies:
        • allkeys-lru
        • volatile-lru
        • allkeys-random
        • volatile-random
        • volatile-ttl
    Benefits:
    • Improved performance for caching and session handling.
    • Enhanced flexibility and customization for individual customers.
    • Better resource management through controlled memory allocation and eviction policies.
    Thank you for considering this feature request. I believe it would be a valuable addition to ISPConfig and greatly benefit the community.
     
  2. variable99

    variable99 Member HowtoForge Supporter

    There is redis ACL. Way more easier to implement, but with less isolation then separate redis instances for each user.
    Here is small shell script to administer such redis users based on ACL:
    Code:
    #!/bin/bash
    # ============================================================
    # Manage Redis ACL users on shared hosting
    # Supports add/del/pass/suspend/resume/list
    # JSON output built via jq
    # ============================================================
    
    REDIS_CLI_BIN="/usr/bin/redis-cli"
    REDIS_CLI="$REDIS_CLI_BIN -s /run/redis/redis.sock --user admin --pass <put_your_pass_here>"
    
    # --- check jq installed ---
    if ! command -v jq >/dev/null 2>&1; then
        echo '{"action":"init","result":"error","message":"jq not installed"}'
        exit 1
    fi
    
    # --- JSON helper ---
    json_output() {
        local action="$1"
        local result="$2"
        local message="$3"
        echo '{}' | jq --arg a "$action" --arg r "$result" --arg m "$message" \
            '.action=$a | .result=$r | .message=$m'
    }
    
    usage() {
        echo '{}' | jq --arg u "Usage: add <username> <password> | del <username> | passwd <username> <password> | suspend <username> | resume <username> | list" \
            '.action="usage" | .result="info" | .message=$u'
        exit 1
    }
    
    # --- sanity checks ---
    if [ $# -lt 1 ]; then
        usage
    fi
    
    ACTION="$1"
    USER="$2"
    PASSWORD="$3"
    
    # --- check redis-cli ---
    if [ ! -x "$REDIS_CLI_BIN" ]; then
        json_output "$ACTION" "error" "redis-cli not found"
        exit 1
    fi
    
    case "$ACTION" in
        add)
            [ -z "$USER" ] || [ -z "$PASSWORD" ] && usage
            $REDIS_CLI ACL SETUSER "$USER" on ">$PASSWORD" "~${USER}:*" "+@all" "-@dangerous" >/dev/null 2>&1
            $REDIS_CLI ACL SAVE >/dev/null 2>&1
            json_output "add" "success" "User '$USER' created with key prefix '${USER}:*'"
            ;;
        del)
            [ -z "$USER" ] && usage
            $REDIS_CLI ACL DELUSER "$USER" >/dev/null 2>&1
            $REDIS_CLI ACL SAVE >/dev/null 2>&1
            json_output "del" "success" "User '$USER' deleted"
            ;;
        passwd)
            [ -z "$USER" ] || [ -z "$PASSWORD" ] && usage
            $REDIS_CLI ACL SETUSER "$USER" ">$PASSWORD" >/dev/null 2>&1
            $REDIS_CLI ACL SAVE >/dev/null 2>&1
            json_output "passwd" "success" "Password for user '$USER' updated"
            ;;
        suspend)
            [ -z "$USER" ] && usage
            $REDIS_CLI ACL SETUSER "$USER" off >/dev/null 2>&1
            $REDIS_CLI ACL SAVE >/dev/null 2>&1
            json_output "suspend" "success" "User '$USER' suspended"
            ;;
        resume)
            [ -z "$USER" ] && usage
            $REDIS_CLI ACL SETUSER "$USER" on >/dev/null 2>&1
            $REDIS_CLI ACL SAVE >/dev/null 2>&1
            json_output "resume" "success" "User '$USER' reactivated"
            ;;
            list)
                    USERS_JSON=$( $REDIS_CLI ACL LIST | while read -r line; do
                            # extract username - it comes after 'user '
                            NAME=$(echo "$line" | grep -oP 'user \K[^ ]+')
                            # extract status: 'on' or 'off' appears as a standalone token
                            STATUS=$(echo "$line" | grep -oE '\bon\b|\boff\b' | head -1)
                            # extract all key patterns (tokens starting with ~) and join them
                            KEYS=$(echo "$line" | grep -oE '~[^ ]+' | jq -R -s -c 'split("\n") | map(select(length > 0))')
                            jq -n --arg n "$NAME" --arg f "$STATUS" --argjson k "$KEYS" \
                                    '{username:$n,status:$f,key_patterns:$k}'
                    done | jq -s '.' )
                    echo '{}' | jq --arg action "list" --argjson users "$USERS_JSON" \
                            '.action=$action | .result="success" | .users=$users'
                    ;;
    
        *)
            usage
            ;;
    esac
     
    ahrasis likes this.
  3. remkoh

    remkoh Active Member HowtoForge Supporter

    Would be great to have within ispc.
    If a customer requests one I now create an instance manually, with a socket file within their website folder.
    Not very practical. That's why they get a socket file from me.
    That is one reason not to.
    And I've seen enough redis-plugins for websites that can't handle such config necessary to operate.
     
    ahrasis likes this.

Share This Page