#! /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. SDK "iphoneos" cannot be located

    在MAC下,交叉编译libvlc出现的一些问题和解决方法.项目中使用了libvlc开源库.在执行编译脚本中,遇到一句xcrun --sdk iphoneos --show-sdk-path报错 mac ...

  2. 【转】强大的vim配置文件,让编程更随意

    原文地址:http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html 花了很长时间整理的,感觉用起来很方便,共享一下. 我的vim配置主 ...

  3. 任务分发系统gearman

    1 Gearman是什么 Gearman Job Server@http://gearman.org/. Gearman 是一个任务分发系统,它提供了一个分发框架,能够分发某类任务到更适合处理这类任务 ...

  4. PHP 中运用 elasticsearch

    PHP扩展安装 1. 环境要求:PHP_VERSION >= 5.3.9,composer工具 2. 在E盘新建文件夹命名为elastic,,拷贝composer.phar到      E:/e ...

  5. 如何彻底隐藏iOS7应用的status bar

    用xcode5开发新的iOS游戏,发现一个坑爹的现象,虽然我已经在info.plist里面把Status bar is initially hidden设置成了YES,但在设备上一跑还是看到丑陋的st ...

  6. UVA12219

    //by Rujia Liu /* 字符串的对比是缓慢的. 鉴于这道题最多只有四个小写字母, 也就是最多26*4种情况, 我们完全可以用整数来代替字符串. 一种比较简单的做法是把字符串看成一个四位的2 ...

  7. PL/pgSQL学习笔记之一

    开始 资料来源:http://www.postgresql.org/docs/9.1/static/plpgsql-overview.html 39.1 概要: PL/pgSQL是一种可载入的过程语言 ...

  8. Educational Codeforces Round 1 B. Queries on a String 暴力

    B. Queries on a String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/59 ...

  9. zoj 3511 Cake Robbery(线段树)

    problemCode=3511" target="_blank" style="">题目链接:zoj 3511 Cake Robbery 题目 ...

  10. psp开发------汉化插件

    近期略微研究了下psp汉化,写了个汉化插件,在这记录下.聊以慰藉. 传统的汉化流程找码表,字库,破解什么这里不多讲,网上有教程.以下说下一种另类汉化方法.特别对于难以破解字库的游戏,当然这样的方法也有 ...