• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.get_redis_instance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mixgene.util.get_redis_instance函数的典型用法代码示例。如果您正苦于以下问题:Python get_redis_instance函数的具体用法?Python get_redis_instance怎么用?Python get_redis_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_redis_instance函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: remove_block

    def remove_block(self, block):
        r = get_redis_instance()
        block_key = ExpKeys.get_block_key(block.uuid)
        pipe = r.pipeline(transaction=True)
        if block.create_new_scope:
            for sub_block_uuid in block.children_blocks:
                sub_block = self.get_block(sub_block_uuid)
                self.remove_block(sub_block)

            pipe.hdel(ExpKeys.get_scope_creating_block_uuid_keys(self.pk), block.sub_scope_name)

        block.on_remove(exp=self)

        # find all bound variables, that provided by this block
        for other_uuid, other_block in self.get_blocks(self.get_all_block_uuids()):
            if other_uuid == block.uuid:
                continue

            for f_name, bound_var in other_block.bound_inputs.items():
                if bound_var.block_uuid == block.uuid:
                    other_block.bound_inputs.pop(f_name)

            self.store_block(other_block)

        # Remove information related to block from redis
        pipe.lrem(ExpKeys.get_exp_blocks_list_key(self.pk), 0, block.uuid)
        pipe.srem(ExpKeys.get_all_exp_keys_key(self.pk), block_key)
        pipe.hdel(ExpKeys.get_blocks_uuid_by_alias(self.pk), block.base_name)

        scope = Scope(self, block.scope_name)
        scope.remove_vars_from_block(block)

        pipe.execute()
开发者ID:craky,项目名称:miXGENE,代码行数:33,代码来源:models.py


示例2: delete_exp

def delete_exp(exp):
    """
        We need to clean 3 areas:
            - keys in redis storage
            - uploaded and created files
            - delete exp object through ORM

        @param exp: Instance of Experiment  to be deleted
        @return: None

    """
    # redis
    r = get_redis_instance()
    all_exp_keys = ExpKeys.get_all_exp_keys_key(exp.pk)
    keys_to_delete = r.smembers(all_exp_keys)
    keys_to_delete.update(all_exp_keys)
    r.delete(keys_to_delete)

    # uploaded data
    data_files = UploadedData.objects.filter(exp=exp)
    for f in data_files:
        try:
            os.remove(f.data.path)
        except:
            pass
        f.delete()
    try:
        shutil.rmtree(exp.get_data_folder())
    except:
        pass

    # deleting an experiment
    exp.delete()
开发者ID:craky,项目名称:miXGENE,代码行数:33,代码来源:models.py


示例3: get_all_scopes_with_block_uuids

    def get_all_scopes_with_block_uuids(self, redis_instance=None):
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        return r.hgetall(ExpKeys.get_scope_creating_block_uuid_keys(self.pk))
开发者ID:craky,项目名称:miXGENE,代码行数:7,代码来源:models.py


示例4: remove_vars_from_block

    def remove_vars_from_block(self, block):
        r = get_redis_instance()
        self.load(r)

        for sv in list(self.scope_vars):
            if sv.block_uuid == block.uuid:
                self.scope_vars.remove(sv)

        self.store(r)
开发者ID:evilkost,项目名称:miXGENE,代码行数:9,代码来源:scope.py


示例5: store

    def store(self, redis_instance=None):
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        key = ExpKeys.get_scope_key(self.exp.pk, scope_name=self.name)
        r.set(key, pickle.dumps(self.scope_vars))
        log.debug("Scope `%s` was saved to storage", self.name)
开发者ID:evilkost,项目名称:miXGENE,代码行数:9,代码来源:scope.py


示例6: change_block_alias

    def change_block_alias(self, block, new_base_name):
        r = get_redis_instance()

        key = ExpKeys.get_blocks_uuid_by_alias(self.pk)
        pipe = r.pipeline()
        pipe.hdel(key, block.base_name)
        pipe.hset(key, new_base_name, block.uuid)
        pipe.execute()
        block.base_name = new_base_name
        self.store_block(block, redis_instance=r)
开发者ID:craky,项目名称:miXGENE,代码行数:10,代码来源:models.py


示例7: auto_exec_task

def auto_exec_task(exp, scope_name, is_init=False):
    r = get_redis_instance()

    lock_key = ExpKeys.get_auto_exec_task_lock_key(exp.pk, scope_name)
    with redis_lock.Lock(r, lock_key):
        try:
            sr = ScopeRunner(exp, scope_name)
            sr.execute(is_init)
        except Exception, e:
            log.exception(e)
开发者ID:evilkost,项目名称:miXGENE,代码行数:10,代码来源:tasks.py


示例8: get_scope_var_value

    def get_scope_var_value(self, scope_var, redis_instance=None):
        """
            @type scope_var: webapp.scope.ScopeVar
        """
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        block = self.get_block(scope_var.block_uuid, r)
        return block.get_out_var(scope_var.var_name)
开发者ID:craky,项目名称:miXGENE,代码行数:11,代码来源:models.py


示例9: get_meta_block_by_sub_scope

    def get_meta_block_by_sub_scope(self, scope_name, redis_instance=None):
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        block_uuid = r.hget(ExpKeys.get_scope_creating_block_uuid_keys(self.pk), scope_name)
        if not block_uuid:
            raise KeyError("Doesn't have a scope with name %s" % scope_name)
        else:
            return self.get_block(block_uuid, r)
开发者ID:craky,项目名称:miXGENE,代码行数:11,代码来源:models.py


示例10: auto_exec_task

def auto_exec_task(exp, scope_name, is_init=False):
    r = get_redis_instance()
    lock_key = ExpKeys.get_auto_exec_task_lock_key(exp.pk, scope_name)
    with redis_lock.Lock(r, lock_key):
        try:
            sr = ScopeRunner(exp, scope_name)
            sr.execute(is_init)
            exp.log("root", "Scope %s finished" % scope_name, "INFO")
        except Exception, e:
            exp.error()
            exp.log("root", e.message, "CRITICAL")
            log.exception(e)
开发者ID:strny,项目名称:miXGENE,代码行数:12,代码来源:tasks.py


示例11: get_all_block_uuids

    def get_all_block_uuids(self, redis_instance=None):
        """
        @param redis_instance: Redis client

        @return: list of block uuids
        """
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        return r.lrange(ExpKeys.get_exp_blocks_list_key(self.pk), 0, -1) or []
开发者ID:craky,项目名称:miXGENE,代码行数:12,代码来源:models.py


示例12: save_file_input

    def save_file_input(self, exp, field_name, file_obj, multiple=False, upload_meta=None):
        if upload_meta is None:
            upload_meta = {}

        if not hasattr(self, field_name):
            raise Exception("Block doesn't have field: %s" % field_name)

        orig_name = file_obj.name
        local_filename = "%s_%s_%s" % (self.uuid[:8], field_name, file_obj.name)

        if not multiple:
            exp.log(self.uuid, "Storing single upload to field: %s" % field_name)
            log.debug("Storing single upload to field: %s", field_name)
            ud, is_created = UploadedData.objects.get_or_create(
                exp=exp, block_uuid=self.uuid, var_name=field_name)

            file_obj.name = local_filename
            ud.data = file_obj
            ud.save()

            ufw = UploadedFileWrapper(ud.pk)
            ufw.orig_name = orig_name
            setattr(self, field_name, ufw)
            exp.store_block(self)
        else:
            exp.log(self.uuid, "Adding upload to field: %s" % field_name)
            log.debug("Adding upload to field: %s", field_name)

            ud, is_created = UploadedData.objects.get_or_create(
                exp=exp, block_uuid=self.uuid, var_name=field_name, filename=orig_name)

            file_obj.name = local_filename
            ud.data = file_obj
            ud.filename = orig_name
            ud.save()

            ufw = UploadedFileWrapper(ud.pk)
            ufw.orig_name = orig_name

            r = get_redis_instance()
            with redis_lock.Lock(r, ExpKeys.get_block_global_lock_key(self.exp_id, self.uuid)):
                exp.log(self.uuid, "Enter lock, file: %s" % orig_name)
                log.debug("Enter lock, file: %s", orig_name)
                block = exp.get_block(self.uuid)
                attr = getattr(block, field_name)

                attr[orig_name] = ufw
                exp.log(self.uuid, "Added upload `%s` to collection: %s" % (orig_name, attr.keys()))
                log.debug("Added upload `%s` to collection: %s", orig_name, attr.keys())
                exp.store_block(block)
                exp.log(self.uuid, "Exit lock, file: %s" % orig_name)
                log.debug("Exit lock, file: %s", orig_name)
开发者ID:andelmi2,项目名称:miXGENE,代码行数:52,代码来源:generic.py


示例13: load

    def load(self, redis_instance=None):
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        key = ExpKeys.get_scope_key(self.exp.pk, scope_name=self.name)
        raw = r.get(key)
        if raw is not None:
            self.scope_vars = pickle.loads(raw)
            # TODO: set scope name during scope_var creation
            for scope_var in self.scope_vars:
                scope_var.scope_name = self.name
开发者ID:evilkost,项目名称:miXGENE,代码行数:13,代码来源:scope.py


示例14: get_ctx

    def get_ctx(self, redis_instance=None):
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        key_context = ExpKeys.get_context_store_key(self.pk)
        pickled_ctx = r.get(key_context)
        if pickled_ctx is not None:
            ctx = pickle.loads(pickled_ctx)
        else:
            raise KeyError("Context wasn't found for exp_id: %s" % self.pk)
        return ctx
开发者ID:craky,项目名称:miXGENE,代码行数:13,代码来源:models.py


示例15: get_all_block_uuids

    def get_all_block_uuids(self, redis_instance=None):
        """
        @type included_inner_blocks: list of str
        @param included_inner_blocks: uuids of inner blocks to be included

        @param redis_instance: Redis client

        @return: list of block uuids
        """
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        return r.lrange(ExpKeys.get_exp_blocks_list_key(self.pk), 0, -1) or []
开发者ID:evilkost,项目名称:miXGENE,代码行数:15,代码来源:models.py


示例16: blocks_resource

def blocks_resource(request, exp_id):
    allowed = ["GET", "POST"]
    if request.method not in allowed:
        return HttpResponseNotAllowed(["GET", "POST"])

    exp = Experiment.objects.get(pk=exp_id)
    r = get_redis_instance()

    new_block = None
    if request.method == "POST":
        try:
            received_block = json.loads(request.body)
        except Exception, e:
            return HttpResponseBadRequest()
        new_block = add_block_to_exp_from_dict(exp, received_block)
开发者ID:evilkost,项目名称:miXGENE,代码行数:15,代码来源:views.py


示例17: get_block_aliases_map

    def get_block_aliases_map(self, redis_instance=None):
        """
        @param redis_instance: Redis

        @return: Map { uuid -> alias }
        @rtype: dict
        """
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        orig_map = r.hgetall(ExpKeys.get_blocks_uuid_by_alias(self.pk))
        return dict([
            (uuid, alias)
            for alias, uuid in orig_map.iteritems()
        ])
开发者ID:craky,项目名称:miXGENE,代码行数:17,代码来源:models.py


示例18: get_block

    def get_block(block_uuid, redis_instance=None):
        """
            @type  block_uuid: str
            @param block_uuid: Block instance identifier

            @type  redis_instance: Redis
            @param redis_instance: Instance of redis client

            @rtype: GenericBlock
            @return: Block instance
        """
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        return pickle.loads(r.get(ExpKeys.get_block_key(block_uuid)))
开发者ID:craky,项目名称:miXGENE,代码行数:17,代码来源:models.py


示例19: post_init

    def post_init(self, redis_instance=None):
        ## TODO: RENAME TO init experiment and invoke on first save
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance

        pipe = r.pipeline()

        pipe.hset(ExpKeys.get_scope_creating_block_uuid_keys(self.pk), "root", None)
        pipe.sadd(ExpKeys.get_all_exp_keys_key(self.pk),[
            ExpKeys.get_exp_blocks_list_key(self.pk),
            ExpKeys.get_blocks_uuid_by_alias(self.pk),
            ExpKeys.get_scope_creating_block_uuid_keys(self.pk),
            ExpKeys.get_scope_key(self.pk, "root")
        ])
        pipe.execute()
开发者ID:craky,项目名称:miXGENE,代码行数:17,代码来源:models.py


示例20: get_blocks

    def get_blocks(block_uuid_list, redis_instance=None):
        """
            @type  block_uuid_list: list
            @param block_uuid_list: List of Block instance identifier

            @type  redis_instance: Redis
            @param redis_instance: Instance of redis client

            @rtype: GenericBlock
            @return: Block instance
        """
        if redis_instance is None:
            r = get_redis_instance()
        else:
            r = redis_instance
        log.debug("getting_blocks: %s", block_uuid_list)
        return [(uuid, pickle.loads(r.get(ExpKeys.get_block_key(uuid))))
                for uuid in block_uuid_list]
开发者ID:craky,项目名称:miXGENE,代码行数:18,代码来源:models.py



注:本文中的mixgene.util.get_redis_instance函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Common.LOG类代码示例发布时间:2022-05-27
下一篇:
Python redis_helper.ExpKeys类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap