qq-22432832

Python批量新增/更新Pika库 On Linux

  • pika安装 (点我进官网)

  • 要插入的数据

任务ID平台value1value2value3
taskaandroid123
taskbios234
taskcother345
# coding=UTF-8
import subprocess

ssh_command = r"redis-cli -h xx.xxx.xxx.xxx -p xxxxx -a 'xxxxxx'"
input_file = r'/home/xxxxxx/zhangjinke/tasks.txt'
with open(input_file,'r') as file:
    file_list = file.readlines()
    for i in file_list:
        data = i.strip().split('\t')
        taskid = data[0]
        channel = data[1]
        send_pv = data[2]
        show_uv = data[3]
        open_uv = data[4]
        command = r'hmset taskid:' + taskid + '@@' + channel + ' send_pv ' + send_pv + ' show_uv ' + show_uv + ' open_uv ' + open_uv
        # print(command)
        a = subprocess.call(ssh_command+' '+command,shell=True)

        if a==0:
            continue
        else:
            print('更新失败:' + i)

posted on 2021-09-29 16:40  春马与夏  阅读(6)  评论(0编辑  收藏  举报  来源

导航