windows 下python 脚本启动多个redis服务
windows,python,脚本,启动,多个,redis,服务
2025-04-11 08:58:00 时间
刚开始用bat脚本写的批量启动,但是一直卡到第一个redis启动,查询尝试无果,果断用python写了一个简单的脚本。
- 附上redis安装目录结构
- 附上程序代码
# 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)
相关文章
- Python-基础03-流程控制
- Easy Games With Python and Pygame(三)- Pygame Event
- 做自动化测试选择Python还是Java?
- Python的使用方法「建议收藏」
- 2022年第 12期《python接口web自动化+测试开发》课程,9月17号开学!
- 用Python的好处
- 【python】Excel转json「建议收藏」
- python计算最大公约数和最小公倍数_python怎么求最大公约数和最小公倍数
- python pip源更换国内镜像,速度加快10倍
- 进制转换python实验五_python进制转换:十进制转二进制的用法「建议收藏」
- 建议收藏!Python 读取千万级数据自动写入 MySQL 数据库
- Python-辨析type/dtype/astype用法
- python skitlearn_Python sklearn
- anaconda和python版本对照表
- Python框架区别是什么?比较常用的框架有哪些?
- 关于Python缩进,我们该了解哪些?
- python——正则表达式(re模块)详解
- Python办公自动化 | word 文本转 excel
- Magic * in Python
- python进制转换函数-Python中进制转换函数的使用