golang 封装"执行shell管理redis(string,集合等)"成api

一 shell脚本

#!/bin/bash

redis-cli -a 123456 -n 0 keys "wbw_0_mid*" | xargs redis-cli -a 123456 -n 0 del
sleep 0.1
redis-cli -a 123456 -n 0 keys "wbw_0_chan*" | xargs redis-cli -a 123456 -n 0 del
sleep 0.1
redis-cli -a 123456 -n 0 keys "wbw_0_ch_mi_*" | xargs redis-cli -a 123456 -n 0 del
sleep 0.1
redis-cli -a 123456 -n 0 ZREMRANGEBYRANK wbw_0_store_lock 0 -1
sleep 0.1

二 golangApi

router.POST("/Reset_wbw_redis", controller.Reset_lm_asa_sv)
func Reset_lm_asa_sv(ctx *gin.Context) {
    ...

    exec.Command("/bin/bash", utils.GlobalObject.Resetsh_path).CombinedOutput()

    

    ...
    ctx.JSON(http.StatusOK, resp)
    return
}

用 exec.Command("/bin/bash", Resetsh_path).CombinedOutput() 命令不会有权限问题

 

posted @ 2021-08-24 18:31  布叔喂丶  阅读(117)  评论(0编辑  收藏  举报