set_ip_pool
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import redis
import urllib2
class RedisConnect:
#class member
__redisId=""
__host=""
__port=""
__db=""
__pwd=""
#Add an element to the collection
def setSadd(self,key,value):
try:
return self.__redisId.sadd(key,value)
except Exception,e:
print e
#Delete an element in a collection.
def srem(self,key,member):
try:
return self.__redisId.srem(key,member)
except Exception,e:
print e
#Get the total number of elements in the collection
def getScard(self,key):
try:
return self.__redisId.scard(key)
except Exception,e:
print e
#Get some member
def getSrandmember(self,key,count):
try:
return self.__redisId.srandmember(key,count)
except Exception,e:
print e
#To determine whether the set in the member
def getSismember(self,key,member):
try:
return self.__redisId.sismember(key,member)
except Exception,e:
print e
#Delete all keys
def delAllKey(self):
try:
return self.__redisId.flushdb()
except Exception,e:
print e
def getIp(count):
url = "http://xvre.daili666api.com/ip/?tid=xxxxxxxxxxx&num=%d"%(count)
req = urllib2.Request(url)
res_data = urllib2.urlopen(req)
res = res_data.read().split("\r\n")
return res
def main():
try:
redis=RedisConnect("xxxxxxxxxx",0000,x,"xxxxxxxxx")
count=redis.getScard("ipPool")
if not count:
Ips=getIp(10000)
for i in Ips:
print "------Is insert ip :%s---------"%i
redis.setSadd("ipPool",i)
if redis.getScard("ipPool")>=1000:
break
else:
ipList=redis.getSrandmember("ipPool",500)
for i in ipList:
print "xxxxxxxxxxIs delete ip :%sxxxxxxxxxxx"%i
redis.srem("ipPool",i)
Ipss=getIp(10000)
m=0
while redis.getScard("ipPool") <1000:
print redis.getScard("ipPool")
print "------Is update ip :%s---------"%Ipss[m]
redis.setSadd("ipPool",Ipss[m])
m+=1
print "--------------------------Update Ip Success----------------------------"
except Exception,e:
print e
#Delete some ip
if __name__ == "__main__":
main()
set_ip_pool的更多相关文章
随机推荐
- Entity Framework Power Tools
http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d
- DB2日期和时间函数汇总
上一篇提到过在DB2中,可以通过SYSIBM.SYSDUMMY1.SYSIBM.DUAL获取寄存器中的值,也可以通过VALUES关键字获取寄存器中的值.则在这篇中,我们直接用VALUES关键字来看看这 ...
- CodeForces 589J Cleaner Robot (DFS,或BFS)
题意:给定n*m的矩阵,一个机器人从一个位置,开始走,如果碰到*或者边界,就顺时针旋转,接着走,问你最后机器人最多能走过多少格子. 析:这个题主要是题意读的不大好,WA了好几次,首先是在*或者边界才能 ...
- 苹果iOS锁屏制作
下面我们开始. 一.锁屏界面 可以观察到,iphone的锁屏界面在时间和解锁部分有着透明强高光风格的背景,高光部分有非常明显的界限,边缘部分1像素的高光也是非常醒目的,整体感觉整个表面非常光滑,如同玻 ...
- no datanode to stop
昨晚整了半天,遇上的问题是通过start-all.sh无法启动datanode,然后关闭时就会报no datanode to stop ,引起这个的原因是因为我多次格式化,导致namespaceID不 ...
- 蓝底白字到图形界面 主板BIOS发展简记
本文转载:http://mb.zol.com.cn/229/2295738.html http://www.360doc.com/content/12/0306/14/1309227_19219857 ...
- 配置iSCSI多路径
1.添加MPIO功能,完成后打开MPIO进行配置,添加对iSCSI多路径的支持,如下图表示已经添加完成后灰色不可选,再打开 MPIO设备 标签页可以看到已安装完成的MPIO所支持的设备:
- getDefinitionByName与ApplicationDomain.getDefinition
主swf 定义:MC,被加载swf 定义:MC.MC1 ①父SWF的应用程序域的新建子域 (默认方式)称其为应用程序域的继承 var app:ApplicationDomain=new Applica ...
- C#中使用GUID的笔记
GUID(全局统一标识符)是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.通常平台会提供生成GUID的API.生成算法很有意思,用到了以太网卡地址.纳秒级时间.芯片ID码和许多可 ...
- [置顶] 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅
转载请注明出处http://blog.csdn.net/xiaanming/article/details/9825113 异步加载图片的例子,网上也比较多,大部分用了HashMap<Strin ...