windows通過python指令碼重啟本地redis
1.檢查redis server是否執行正常
def check_server():
conn = redis.StrictRedis(
host="127.0.0.1",
port=6379,
db=0,
socket_timeout=5, # 發出命令接收響應的時間不能超過此引數設定時間
socket_connect_timeout=5 # 建立連線超時時間
)
flag = False
try:
res = conn.get('a')
flag = True
except Exception as e:
# print('check_server error: %s' % e)
print(traceback.format_exc())
return flag
2.獲取redis server程式id
def get_server_pid():
import psutil
spid = 0
for process in psutil.process_iter():
# info = process.as_dict(attrs=['name', 'pid'])
name = process.name()
pid = process.pid
if name == 'redis-server.exe':
# print(pid, type(pid))
spid = pid
break
return spid
3.關掉之前的程式
def do_kill(pid):
cmd = 'taskkill /pid ' + str(pid) + ' /f'
try:
os.system(cmd)
except Exception as e:
print('do_kill error: %s, pid: %s' % (e, pid))
4.重啟redis server
def restart_redis_server():
# 直接通過命令列啟動redis server,無法得到之前redis server的資料,所以採用這種方式重啟redis
cmd = r'start C:\work\redis_server_restart.bat'
# print(cmd)
result = 10086
try:
result = os.system(cmd)
except Exception as e:
print('restart restart_redis_server: %s' % e)
return result
對應的redis_server_restart.bat指令碼:
@echo off
title redis-server
::set ENV_HOME="D:\redis"
::D:
set ENV_HOME="C:\Users\Administrator\Desktop\redis"
C:
color 0a
cd %ENV_HOME%
redis-server.exe redis.windows.conf
::exit
相關文章
- redis重啟指令碼Redis指令碼
- redis多例項重啟指令碼薦Redis指令碼
- 通過 Redis 定時執行指令碼Redis指令碼
- Windows下通過指令碼快速修改IP地址Windows指令碼
- Windows監控並重啟某個程式指令碼Windows指令碼
- nginx重啟指令碼Nginx指令碼
- Nginx 重啟指令碼Nginx指令碼
- MacOS 啟動 -- Redis指令碼MacRedis指令碼
- redis 帶密碼重啟Redis密碼
- 通過shell指令碼分析足彩指令碼
- 通過Python指令碼理解系統執行緒薦Python指令碼執行緒
- windows客戶端通過指令碼檔案新增信任站點薦Windows客戶端指令碼
- windows下用指令碼設定本地連線ipWindows指令碼
- SpringBoot(18)---通過Lua指令碼批量插入資料到Redis布隆過濾器Spring Boot指令碼Redis過濾器
- 通過shell定製ash指令碼指令碼
- 通過impdp匯出索引指令碼索引指令碼
- 分享一份nginx重啟指令碼Nginx指令碼
- .net 程式通過 crontab 無法啟動,手動執行指令碼可以啟動指令碼
- Redis大key掃描Python指令碼RedisPython指令碼
- 分享一例指令碼發版和tomcat重啟指令碼指令碼Tomcat
- windows下oracle自動啟動指令碼WindowsOracle指令碼
- 通過shell指令碼防止埠掃描指令碼
- 通過shell指令碼檢視鎖資訊指令碼
- 通過shell指令碼監控oracle session指令碼OracleSession
- 【原始碼】Redis Server啟動過程原始碼RedisServer
- IIS8應用池重啟指令碼指令碼
- linux 上 jenkins 通過節點服務在 windows 執行指令碼LinuxJenkinsWindows指令碼
- 通過oracle的指令碼研究其建庫過程Oracle指令碼
- Redis - Lua 指令碼Redis指令碼
- Redis的指令碼Redis指令碼
- 記windows自定義bat指令碼自啟動WindowsBAT指令碼
- Windows下Oracle服務啟停bat指令碼WindowsOracleBAT指令碼
- 通過shell指令碼 批量新增使用者指令碼
- 通過shell指令碼新增備庫日誌指令碼
- 通過shell指令碼來統計段大小指令碼
- 通過shell指令碼檢視procedure的資訊指令碼
- 通過shell指令碼檢視package的資訊指令碼Package
- 走近原始碼:Redis的啟動過程原始碼Redis