一允瞧、python操作redis
1匆光、python使用redis連接池
pool = ConnectionPool(host = 'xxxxxx', port=xxx, decode_responses=True, socket_connect_timeout=1,retry_on_timeout=True)
redis = Redis(connection_pool=pool)
socket_connect_timeout:設(shè)置連接redis的超時時間们豌,此處設(shè)置為1s「防止連接redis超時要等待很久」
retry_on_timeout=True:鏈接redis超時冰寻,為True自動斷開重連蛇券;默認(rèn)為False
二缔恳、序列化和反序列化
1剃毒、要是遇到uncode這個類型的參數(shù)病袄,dict搂赋、list、list里面的參數(shù)等益缠,不管怎么encode脑奠、decode都沒有實(shí)現(xiàn)你要的參數(shù)類型,試試eval左刽,真的好用捺信!
三、建立集合欠痴、列表等
1迄靠、for i,j in zip(range(0,len(bid_cases_list_sorted)),range(1,len(bid_cases_list_sorted)))
功能:for循環(huán),兩個列表
2喇辽、bid_cases_list_sorted = sorted(bid_cases_list,key=attrgetter('priority','price'),reverse = True)
功能:排序掌挚,list中是類對象,先按照priority排序菩咨、再按照price排序吠式,reverse = True表示降序(就是最終排序的結(jié)果,第一個是最大的抽米;若沒有這一項(xiàng)特占,則默認(rèn)升序)
3、bid_party_ids = set()
bid_party_ids.add(bid_cases_list_sorted[0].party_id)
功能:建立set集合云茸,用add方法插入數(shù)據(jù)