當前位置: 首頁>>代碼示例>>Python>>正文


Python redis.call方法代碼示例

本文整理匯總了Python中redis.call方法的典型用法代碼示例。如果您正苦於以下問題:Python redis.call方法的具體用法?Python redis.call怎麽用?Python redis.call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis的用法示例。


在下文中一共展示了redis.call方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def __init__(self, *args, **kwargs):
            """Initialize atomic integer instance.

            :param initial_value: Optional. The initial value of this
                variable in case it doesn't exist in Redis yet.
            """
            super().__init__(*args, **kwargs)
            self._lua_add = ManagerState.LuaFunction(self, "oldval + arg", short=True)
            self._lua_mul = ManagerState.LuaFunction(self, "oldval * arg", short=True)
            self._lua_floordiv = ManagerState.LuaFunction(
                self, "floor(oldval / arg)", short=True
            )
            self._lua_cas = ManagerState.LuaFunction(
                self,
                """
                local oldval = tonumber(redis.call('EXISTS', KEYS[1]) and redis.call('GET', KEYS[1]) or ARGV[3])
                if oldval == tonumber(ARGV[1]) then
                    redis.call('SET', KEYS[1], tonumber(ARGV[2]))
                    return 1
                else
                    return 0
                end
            """,
            )
            self.initial_value = kwargs.get("initial_value", 0) 
開發者ID:genialis,項目名稱:resolwe,代碼行數:27,代碼來源:state.py

示例2: gather_stage

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def gather_stage(harvester, job):
    '''Calls the harvester's gather_stage, returning harvest object ids, with
    some error handling.

    This is split off from gather_callback so that tests can call it without
    dealing with queue stuff.
    '''
    job.gather_started = datetime.datetime.utcnow()

    try:
        harvest_object_ids = harvester.gather_stage(job)
    except (Exception, KeyboardInterrupt):
        harvest_objects = model.Session.query(HarvestObject).filter_by(
            harvest_job_id=job.id
        )
        for harvest_object in harvest_objects:
            model.Session.delete(harvest_object)
        model.Session.commit()
        raise
    finally:
        job.gather_finished = datetime.datetime.utcnow()
        job.save()
    return harvest_object_ids 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:25,代碼來源:queue.py

示例3: test_execute_pipeline_script

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def test_execute_pipeline_script(self, can_replicate_commands):
        if not self.scripts.can_replicate_commands:
            assert False, 'test suite needs Redis 3.2 or higher'

        self.scripts._can_replicate_commands = can_replicate_commands

        self.conn.script_flush()

        s = self.conn.register_script("redis.call('set', 'x', 'y')")

        # Uncached execution
        p = self.conn.pipeline()
        s(client=p)
        self.scripts.execute_pipeline(p)
        assert self.conn.get('x') == 'y'

        self.conn.delete('x')

        # Cached execution
        p = self.conn.pipeline()
        s(client=p)
        self.scripts.execute_pipeline(p)
        assert self.conn.get('x') == 'y' 
開發者ID:closeio,項目名稱:tasktiger,代碼行數:25,代碼來源:test_redis_scripts.py

示例4: consume

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def consume(self):
        """Consume value gotten from queue.
        Raise UserWarning if consume() called before get()
        """
        if self._item is None:
            raise UserWarning("Must call get() before consume()")

        self.LOCKS.pop(self._h_k)

        rv = raw_client().evalsha(
            self._SHAS['lq_consume'],
            len(self.SCRIPTS['lq_consume']['keys']),
            self._h_k, self._path, self._q_lookup, self._client_id)
        assert rv == 1

        self._h_k = None
        self._item = None 
開發者ID:sailthru,項目名稱:stolos,代碼行數:19,代碼來源:qbcli_redis.py

示例5: _upload_batch_continuing

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def _upload_batch_continuing(self, queue):
        ret = {
            "count": 0
        }

        res = self._upload_batch(queue)  # Remember this call will raise exception upon server error

        ret["count"] = res["count"]
        if "error" in res:
            ret["error"] = res["error"]

        # Continue to upload if more pending batches present
        while not "error" in res and (res["count"] == self.options.get("max_batch_size", 100) or res.get("continue", False)):
            res = self._upload_batch(queue)  # Remember this call will raise exception upon server error

            ret["count"] += res["count"]
            if "error" in res:
                ret["error"] = res["error"]

        return ret 
開發者ID:autopi-io,項目名稱:autopi-core,代碼行數:22,代碼來源:cloud_cache.py

示例6: upload_pending

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def upload_pending(self):
        ret = {
            "total": 0,
        }

        try:
            res = self._upload_batch_continuing(self.PENDING_QUEUE)  # Remember this call will raise exception upon server error
            ret["total"] += res["count"]

            if "error" in res:
                ret.setdefault("errors", []).append(res["error"])

        except RequestException as rex:
            ret.setdefault("errors", []).append(str(rex))

            # Retry queue logic is moved to '_upload_batch' method

        return ret 
開發者ID:autopi-io,項目名稱:autopi-core,代碼行數:20,代碼來源:cloud_cache.py

示例7: script_load

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def script_load(script):
    sha = [None]                #A
    def call(conn, keys=[], args=[], force_eval=False):   #B
        if not force_eval:
            if not sha[0]:   #C
                sha[0] = conn.execute_command(              #D
                    "SCRIPT", "LOAD", script, parse="LOAD") #D
    
            try:
                return conn.execute_command(                    #E
                    "EVALSHA", sha[0], len(keys), *(keys+args)) #E
        
            except redis.exceptions.ResponseError as msg:
                if not msg.args[0].startswith("NOSCRIPT"):      #F
                    raise                                       #F
        
        return conn.execute_command(                    #G
            "EVAL", script, len(keys), *(keys+args))    #G
    
    return call             #H
# <end id="script-load"/>
#A Store the cached SHA1 hash of the result of SCRIPT LOAD in a list so we can change it later from within the call() function
#B When calling the "loaded script", you must provide the connection, the set of keys that the script will manipulate, and any other arguments to the function
#C We will only try loading the script if we don't already have a cached SHA1 hash
#D Load the script if we don't already have the SHA1 hash cached
#E Execute the command from the cached SHA1
#F If the error was unrelated to a missing script, re-raise the exception
#G If we received a script-related error, or if we need to force-execute the script, directly execute the script, which will automatically cache the script on the server (with the same SHA1 that we've already cached) when done
#H Return the function that automatically loads and executes scripts when called
#END 
開發者ID:fuqi365,項目名稱:https---github.com-josiahcarlson-redis-in-action,代碼行數:32,代碼來源:ch11_listing_source.py

示例8: queue_purge

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def queue_purge(self, queue=None):
        '''
        Purge the consumer's queue.

        The ``queue`` parameter exists only for compatibility and is
        ignored.
        '''
        # Use a script to make the operation atomic
        lua_code = b'''
            local routing_key = KEYS[1]
            local message_key = ARGV[1]
            local count = 0
            while true do
                local s = redis.call("lpop", routing_key)
                if s == false then
                    break
                end
                local value = cjson.decode(s)
                local id = value[message_key]
                local persistance_key = routing_key .. ":" .. id
                redis.call("del", persistance_key)
                count = count + 1
            end
            return count
        '''
        script = self.redis.register_script(lua_code)
        return script(keys=[self.routing_key], args=[self.message_key]) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:29,代碼來源:queue.py

示例9: _upload_batch

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def _upload_batch(self, queue):
        ret = {
            "count": 0
        }

        source_queue = re.sub(self.WORK_QUEUE_REGEX, "", queue)  # Remove suffix if already a work queue
        work_queue = self.WORK_QUEUE.format(source_queue)

        # Pop next batch into work queue
        batch = self._dequeue_batch(source_queue, work_queue, self.options.get("max_batch_size", 100))
        if not batch:
            if log.isEnabledFor(logging.DEBUG):
                log.debug("No batch found to upload from queue '{:}'".format(queue))

            return ret

        # Upload batch
        payload = self._prepare_payload_for(batch)
        ok, msg = self._upload(payload)  # Remember this call will raise exception upon server error
        if ok:
            log.info("Uploaded batch with {:} entries from queue '{:}'".format(len(batch), queue))

            ret["count"] = len(batch)

            # Batch uploaded equals work completed
            self.client.pipeline() \
                .delete(work_queue) \
                .bgsave() \
                .execute()
        else:
            log.warning("Temporarily unable to upload batch with {:} entries from queue '{:}': {:}".format(len(batch), queue, msg))

            ret["error"] = msg

        return ret 
開發者ID:autopi-io,項目名稱:autopi-core,代碼行數:37,代碼來源:cloud_cache.py

示例10: upload_failing

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def upload_failing(self):
        ret = {
            "total": 0,
        }

        queues = self.list_queues(pattern="fail_*")  # This will also include work queues if present
        if queues:
            log.warning("Found {:} fail queue(s)".format(len(queues)))

        try:
            for queue in queues:
                res = self._upload_batch_continuing(queue)  # Remember this call will raise exception upon server error
                ret["total"] += res["count"]

                # Stop upon first error
                if "error" in res:
                    ret.setdefault("errors", []).append(res["error"])

                    break

        except RequestException as rex:
            ret.setdefault("errors", []).append(str(rex))

            log.warning("Still unable to upload failed batch(es): {:}".format(rex))

        return ret 
開發者ID:autopi-io,項目名稱:autopi-core,代碼行數:28,代碼來源:cloud_cache.py

示例11: script_load

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def script_load(script):
    # 將 SCRIPT LOAD 命令返回的已緩存腳本 SHA1 校驗和儲存到一個列表裏麵,
    # 以便之後在 call() 函數內部對其進行修改。
    sha = [None]                
    # 在調用已載入腳本的時候,
    # 用戶需要將 Redis 連接、腳本要處理的鍵以及腳本的其他參數傳遞給腳本。
    def call(conn, keys=[], args=[], force_eval=False):  
        if not force_eval:
            # 程序隻會在 SHA1 校驗和未被緩存的情況下嘗試載入腳本。
            if not sha[0]:   
                # 如果 SHA1 校驗和未被緩存,那麽載入給定的腳本
                sha[0] = conn.execute_command(              
                    "SCRIPT", "LOAD", script, parse="LOAD") 
    
            try:
                # 使用已緩存的 SHA1 校驗和執行命令。
                return conn.execute_command(                    
                    "EVALSHA", sha[0], len(keys), *(keys+args)) 
        
            except redis.exceptions.ResponseError as msg:
                # 如果錯誤與腳本缺失無關,那麽重新拋出異常。
                if not msg.args[0].startswith("NOSCRIPT"):      
                    raise                                       
        
        # 當程序接收到腳本錯誤的時候,
        # 又或者程序需要強製執行腳本的時候,
        # 它會使用 EVAL 命令直接執行給定的腳本。
        # EVAL 命令在執行完腳本之後,
        # 會自動地把腳本緩存起來,
        # 而緩存產生的 SHA1 校驗和跟使用 EVALSHA 命令緩存腳本產生的 SHA1 校驗和是完全相同的。
        return conn.execute_command(                   
            "EVAL", script, len(keys), *(keys+args))   
    
    # 返回一個函數,這個函數在被調用的時候會自動載入並執行腳本。
    return call            
# <end id="script-load"/> 
開發者ID:huangz1990,項目名稱:riacn-code,代碼行數:38,代碼來源:ch11_listing_source.py

示例12: __call__

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def __call__(self, record_id):
        # Support DAL shortcut query: table(record_id)

        q = self.id  # This will call the __getattr__ below
                     # returning a MockQuery

        # Instructs MockQuery, to behave as db(table.id == record_id)
        q.op = 'eq'
        q.value = record_id

        row = q.select()
        return row[0] if row else Storage() 
開發者ID:uwdata,項目名稱:termite-visualizations,代碼行數:14,代碼來源:redis_session.py

示例13: __init__

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def __init__(self, ring_size):  # type: (int) -> None
        self.metrics_counter_getter = None  # type: Optional[Callable[[six.text_type], Counter]]

        # These should not be overridden by subclasses. The standard or Sentinel base class determines the ring size
        # and passes it in, and then we create a randomized cycle-iterator (which can be infinitely next-ed) of
        # connection indexes to use for choosing a connection when posting to request queues (response queues use a
        # consistent hashing algorithm).
        self._ring_size = ring_size
        self._connection_index_generator = itertools.cycle(random.sample(range(self._ring_size), k=self._ring_size))

        # It doesn't matter which connection we use for this. The underlying socket connection isn't even used (or
        # established, for that matter). But constructing a Script with the `redis` library requires passing it a
        # "default" connection that will be used if we ever call that script without a connection (we won't).
        self.send_message_to_queue = SendMessageToQueueCommand(self._get_connection(0)) 
開發者ID:eventbrite,項目名稱:pysoa,代碼行數:16,代碼來源:base.py

示例14: deleteBanchoSessions

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def deleteBanchoSessions(self):
		"""
		Remove all `peppy:sessions:*` redis keys.
		Call at bancho startup to delete old cached sessions

		:return:
		"""
		try:
			# TODO: Make function or some redis meme
			glob.redis.eval("return redis.call('del', unpack(redis.call('keys', ARGV[1])))", 0, "peppy:sessions:*")
		except redis.RedisError:
			pass 
開發者ID:osuripple,項目名稱:pep.py,代碼行數:14,代碼來源:tokenList.py

示例15: _lookup_clublogAPI

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import call [as 別名]
def _lookup_clublogAPI(self, callsign=None, timestamp=None, url="https://secure.clublog.org/dxcc", apikey=None):
        """ Set up the Lookup object for Clublog Online API
        """

        params = {"year" : timestamp.strftime("%Y"),
            "month" : timestamp.strftime("%m"),
            "day" : timestamp.strftime("%d"),
            "hour" : timestamp.strftime("%H"),
            "minute" : timestamp.strftime("%M"),
            "api" : apikey,
            "full" : "1",
            "call" : callsign
        }

        if timestamp is None:
            timestamp = datetime.utcnow().replace(tzinfo=UTC)

        if sys.version_info.major == 3:
            encodeurl = url + "?" + urllib.parse.urlencode(params)
        else:
            encodeurl = url + "?" + urllib.urlencode(params)
        response = requests.get(encodeurl, timeout=5)

        if not self._check_html_response(response):
            raise LookupError

        jsonLookup = response.json()
        lookup = {}

        for item in jsonLookup:
            if item == "Name": lookup[const.COUNTRY] = jsonLookup["Name"]
            elif item == "DXCC": lookup[const.ADIF] = int(jsonLookup["DXCC"])
            elif item == "Lon": lookup[const.LONGITUDE] = float(jsonLookup["Lon"])*(-1)
            elif item == "Lat": lookup[const.LATITUDE] = float(jsonLookup["Lat"])
            elif item == "CQZ": lookup[const.CQZ] = int(jsonLookup["CQZ"])
            elif item == "Continent": lookup[const.CONTINENT] = jsonLookup["Continent"]

        if lookup[const.ADIF] == 0:
            raise KeyError
        else:
            return lookup 
開發者ID:dh1tw,項目名稱:pyhamtools,代碼行數:43,代碼來源:lookuplib.py


注:本文中的redis.call方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。