标签:nbsp main pytho bsp glob 频率 redis pre span
# -*- coding:utf-8 -*- import redis redis_cli = None def init_redis(): global redis_cli if not redis_cli: redis_cli = redis.Redis(host=‘127.0.0.1‘, port=6379, db=0) def test(func): def warp(*args, **kwargs): func_name = func.__name__ global redis_cli if redis_cli.get(func_name): return ‘请求太快了‘ else: redis_cli.set(func_name, func_name, ex=10) return func(*args, **kwargs) return warp @test def get_plus(a, b): return a+b if __name__ == ‘__main__‘: init_redis() aa = get_plus(1, 2)
标签:nbsp main pytho bsp glob 频率 redis pre span
原文地址:http://www.cnblogs.com/xxj1988/p/7143444.html