nginx-lua取後端redis keyが配列である場合のランダム取値.

410 ワード

#ミリ秒単位の値math.randomseed(tostring(os.time()):reverse():sub(1, 7))は、サーバipの値が2つであると仮定する、13,24 action2={13,24}配列要素数が1 if (#action2) > 1 thenより大きい場合、サーバipをaction 2の複数の要素値のうちの1つに再割り当てする.action2=action2[math.random(#action2)]再割り当て後のaciton 2(サーバip)print (action2) end以降action 2=redisのいずれかのkey/valueを自分で制御でき、value数>1でランダムに値を取り、nginxに戻る