Python 官方文档:入门教程 => 点击学习
#!/usr/bin/env python#coding=utf-8import Mysqldbimport Redisimport osimport Socket,fcntl,struct#print redis._file_def ge
#!/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()
未完待续
--结束END--
本文标题: python 分析redis
本文链接: https://www.lsjlt.com/news/185148.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0