async def bulk_update(new_data: List[CurrencyRecord], invalidate_others: bool, redis: Redis): if invalidate_others: await redis.flushdb() tr = redis.multi_exec() for one_line in new_data: tr.set(str((one_line.source, one_line.dest)), one_line.price) tr.set(str((one_line.dest, one_line.source)), 1. / one_line.price) await tr.execute()
async def _get_namespace(cls, redis: Redis, global_keys: GlobalKeys, user: str) -> bytes: user_key = user.encode('utf-8') new_namespace = uuid.uuid4().hex.encode('ascii') ns_val = b'%d/%b' % (DATA_VERSION, new_namespace) multi = redis.multi_exec() multi.hsetnx(global_keys.namespaces, user_key, ns_val) multi.hget(global_keys.namespaces, user_key) _, ns_val = await multi.execute() version, namespace = ns_val.split(b'/', 1) if int(version) != DATA_VERSION: raise IncompatibleData() return namespace
async def _cleanup(self, conn: aioredis.Redis, sid: str) -> None: logger.debug("cleaning up scheduler data: sid=%s", sid) async for worker_id, job_data in conn.ihscan(self._stash_key, match=f'{sid}#*'): job_id, run_at = job_data.decode().split(',') logger.debug("releasing dead job: sid=%s, id=%s, run_at=%s", sid, job_id, run_at) with await self._conn_pool as conn: tx = conn.multi_exec() tx.zadd(self._timeline_key, float(run_at), job_id) tx.hdel(self._stash_key, worker_id) await tx.execute() await conn.hdel(self._heartbeats_key, field=sid)
async def _get_password(cls, redis: Redis, config: Config, name: str) -> Tuple[str, bytes]: key = config.users_key.format(name=name) multi = redis.multi_exec() if config.users_hash is None: multi.get(key) else: multi.hget(config.users_hash, key) new_namespace = uuid.uuid4().hex.encode('ascii') multi.hsetnx(config.namespace_hash, key, new_namespace) multi.hget(config.namespace_hash, key) value, _, namespace = await multi.execute() if value is None: raise InvalidAuth() elif config.users_json: value_obj = json.loads(value) try: return value_obj['password'], namespace except KeyError as exc: raise InvalidAuth() from exc else: return value.decode('utf-8'), namespace