#!/bin/sh
# @function install Redis server
function InstallRedisServer()
{
    ShowResult "[green]正在安装redis-server... [/green]" 1
    
    # install
    eval cd ${_PATH_COMPILATION_} ${_SYS_SHOW_INSTALL_DETAILS_}
    eval rm -rf ./redis-4.0.9 ${_SYS_SHOW_INSTALL_DETAILS_}
    eval tar zxvf ${_PATH_SOFTWARE_}/redis-4.0.9.* ${_SYS_SHOW_INSTALL_DETAILS_}
    eval cd redis-4.0.9 ${_SYS_SHOW_INSTALL_DETAILS_}
    eval make MALLOC=jemalloc ${_SYS_MAKE_EXT_} ${_SYS_SHOW_INSTALL_DETAILS_}
    eval make install ${_SYS_SHOW_INSTALL_DETAILS_}
    eval cd utils ${_SYS_SHOW_INSTALL_DETAILS_}
    _REDIS_PORT_=${_REDIS_PORT_:-6379}
    export PATH=$PATH:/usr/local/bin
    # install service
    ./install_server.sh <<EOF


${_PATH_LOG_}/redis_${_REDIS_PORT_}.log
${_PATH_REDIS_DATA_}

EOF

     # replace conf
    eval \cp -f ${_PATH_CONFIGS_}/redis.conf.tpl /etc/redis/${_REDIS_PORT_}.conf ${_SYS_SHOW_INSTALL_DETAILS_}
    sed -ri "
        s@\{_port_\}@${_REDIS_PORT_}@g;
        s@\{_internal_ip_\}@$(ifconfig ${_NET_INTERNAL_ADAPTER_} 2>/dev/null | grep inet | cut -d: -f2 | cut -d' ' -f1)@g;
        " /etc/redis/${_REDIS_PORT_}.conf
    
    eval \service redis_${_REDIS_PORT_} stop ${_SYS_SHOW_INSTALL_DETAILS_}
    
    ShowStatus $?
}

# @function install libhiredis
function InstallHiredisLib()
{
    ShowResult "[green]正在解压hiredis库... [/green]" 1
    
    cd /usr/lib64
    eval tar zxvf ${_PATH_SOFTWARE_}/libhiredis.tar.gz ${_SYS_SHOW_INSTALL_DETAILS_}
    ldconfig
    
    ShowStatus $?
}