def store_interface(config, interface, key=None, exist='SET_IF_NOT_EXIST'):
redis = yield from aioredis.create_redis((config.redis_host, config.redis_port))
pipe = redis.pipeline()
interface_id = interface['network_interface_id']
# Only store picked interface data if using default key (not fixed key from instance)
if not key:
key = KEY_ENI + interface_id
pipe.set(key=KEY_ENI + interface_id, value=pickle.dumps(interface), expire=int(config.redis_ttl))
# Store intermediate key lookups so that we can find metadata given only an IP address
if 'association' in interface:
pipe.set(key=KEY_IP + interface['association']['public_ip'], value=key, expire=int(config.redis_ttl), exist=exist)
for address in interface.get('private_ip_addresses', []):
pipe.set(key=KEY_IP + address['private_ip_address'], value=key, expire=int(config.redis_ttl), exist=exist)
yield from pipe.execute()
redis.close()
yield from redis.wait_closed()
评论列表
文章目录