#! /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的更多相关文章

随机推荐

  1. 转】Maven学习总结(七)——eclipse中使用Maven创建Web项目

    原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4054814.html 感谢! 一.创建Web项目 1.1 选择建立Maven Project 选择File -& ...

  2. thymeleaf中的模板布局

    一.包括模板片段: 1:定义和引用片段,我们经常会想要包含在模板片段来自其他模板.常见的用途是页脚.标题.菜单…; 为了做到这一点,Thymeleaf需要我们定义包含可用的片段,我们可以通过使用th: ...

  3. C#学习笔记(十六):Attribute

    Attribute可以为类或方法添加一些附加的信息,我们可以看看MSDN对Attribute的描述: 公共语言运行时允许你添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注 ...

  4. 【数据库】MySql常用函数梳理

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/5866388.html MySql常用函数梳理: 1:数学函数 使用格式:一般用于插入.修改语句中,直接 函数( ...

  5. .Net 揭密--JIT怎样运行你的代码

    方法调用: 第一部分 (普通调用) 译者:我们都知道.NET托管代码如C#.VB.NET写成的代码,都是先被编译成中间语言(IL,Intermediate Language,在运行时,再由即时编译器( ...

  6. word2007 每页显示表头

    word2007 每页显示表头 在Word 2007文档中,如果一张表格需要在多页中跨页显示,则设置标题行重复显示很有必要,因为这样会在每一页都明确显示表格中的每一列所代表的内容.在Word 2007 ...

  7. android ipc通信机制之二序列化接口和Binder

    IPC的一些基本概念,Serializable接口,Parcelable接口,以及Binder.此核心为最后的IBookManager.java类!!! Serializable接口,Parcelab ...

  8. xcode7.3 iTunes Store operation failed问题

    升级了7.3,真心的不好用啊,bug一堆,写个代码,引入的类根本找不到,必须要command+b 重新编译一遍,现在连提交appstore都有问题. 果断用了 Application Loader上传 ...

  9. 错误内存【读书笔记】C程序中常见的内存操作有关的典型编程错误

    题记:写这篇博客要主是加深自己对错误内存的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢. 对C/C++程序员来讲,内存管理是个不小的挑战,绝对值得慎之又慎,否则让由上万行代码构成的 ...

  10. PI-利用SoapUI 测试web service的方法介绍

    在运用webservice调用数据的过程中,非常关键的一个步骤就是获取到webservice的地址,并测试webservice的连通情 况,webservice的连通测试主要是两个方面:1,查看web ...