前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >windows 下python 脚本启动多个redis服务

windows 下python 脚本启动多个redis服务

作者头像
友儿
发布2022-09-11 17:18:41
8920
发布2022-09-11 17:18:41
举报
文章被收录于专栏:友儿友儿

刚开始用bat脚本写的批量启动,但是一直卡到第一个redis启动,查询尝试无果,果断用python写了一个简单的脚本。

  • 附上redis安装目录结构
  • 附上程序代码
代码语言:javascript
复制
# python >=2.x
import os
import threading


def makefile(_path, _name, _content):
    # type: (str, str, str) -> str
    filer = _path + _name
    if not os.path.exists(_path):
        print('the path is not exists')
    else:
        if not os.path.isdir(_path):
            print('the dir name is not exists')
        else:
            if not os.path.isfile(filer):
                f = open(filer, 'w+')
                f.write(_content)
                f.seek(0)
            else:
                print(filer + ' exists')


def execute_cmd_command(command_str, f, tags):
    command_str = command_str + ' D:\phpstudy_pro\Extensions\\redis3.0.504\config\\' + f + '>>D:\dev\python\logs\\' + tags + '_log.txt 2>&1'
    os.system(command_str)


def file_name(file_dir, _names):
    # type: (str) -> str
    system = str('D:\phpstudy_pro\Extensions\\redis3.0.504\\redis-server.exe')  # type: str
    if not os.path.isfile(system):
        pass
    else:
        for root, dirs, files in os.walk(file_dir):
            for f in files:
                if str(os.path.splitext(f)[0]) + str(os.path.splitext(f)[1]) in _names:
                    if os.path.splitext(f)[1] == '.conf':
                        t = threading.Thread(target=execute_cmd_command, args=(system, f, os.path.splitext(f)[0]))
                        t.start()


default = '6379,6380,6381'  # type: str

source = input('Enter your input eg(6379,6380,6381): ')

source = default if len(source) == 0 else source

ports = source.split(',')

names = []
for port in ports:
    path = str('D:\phpstudy_pro\Extensions\\redis3.0.504\config\\')
    name = str('redis-' + port + '.conf')
    names.append(name)
    content = str('bind 127.0.0.1\nport ' + port + '\ntimeout 65\nmaxclients 10000\ndatabases 16\nmaxmemory 1048576000')
    makefile(path, name, content)

conf = 'D:\phpstudy_pro\Extensions\\redis3.0.504\config\\'

file_name(conf, names)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 刚开始用bat脚本写的批量启动,但是一直卡到第一个redis启动,查询尝试无果,果断用python写了一个简单的脚本。
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档