前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 分析redis

python 分析redis

作者头像
py3study
发布2020-01-13 10:53:20
3870
发布2020-01-13 10:53:20
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
#!/usr/bin/env python
#coding=utf-8
import MySQLdb
import redis
import os
import socket,fcntl,struct
#print redis._file_
def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
                s.fileno(),
                0x8915, # SIOCGIFADDR
                struct.pack('256s', ifname[:15])
                )[20:24])
ip = get_ip_address('eth0')
r = redis.Redis(host='192.168.100.89',port=6379,db=1)
info = r.info()
wr = open("a.txt",'w')
for key in info:
    wr.write('%s  %s\n'  % (key, info[key]))
wr.close()
file_object = open('a.txt')
try:
    all_the_text = file_object.read()
finally:
    file_object.close()
print type(all_the_text)
print all_the_text
db = MySQLdb.connect(user='root', db='redisinfo', passwd='llllll', host='localhost')
cursor = db.cursor()
sql_content = "insert into info_product(ip,name,jifang,redisinfo) values('%s', '%s', '%s', \"%s\")"%(ip,"tes111t","GZ",all_the_text)
print sql_content
cursor.execute(sql_content)
db.commit()
db.close()
cursor.close()
未完待续
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档