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


Python Redis.zscore方法代碼示例

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


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

示例1: RedisSocketManager

# 需要導入模塊: from redis.client import Redis [as 別名]
# 或者: from redis.client.Redis import zscore [as 別名]

#.........這裏部分代碼省略.........

    def lock_socket(self, sessid):
        """Locks the given session to the local socket for the  duration of a ``with`` block.
        
        Entering the ``with`` block returns a socket with ``sessid`` or None if it was not handshaken yet.
        
        Example:
        
            with manager.lock_socket('12345678') as socket:
                if socket:
                    socket.do_something()
                else:
                    bad_session()
                    
        """

        return SessionContextManager(self, sessid)

    def heartbeat_received(self, sessid):
        """Called when a heartbeat for the given socket arrives.
        """
        socket = self.sockets.get(sessid)
        if socket:
            self.redis.zadd(self.sockets_key, sessid, str(time.time()))
        super(RedisSocketManager, self).heartbeat_received(sessid)

    def handshake(self, sessid):
        """Don't create the socket yet, just mark the session as existing.
        """
        # Socket ids are kept in a sorted set, with score the latest heartbeat
        self.redis.zadd(self.sockets_key, sessid, str(time.time()))

    def is_handshaken(self, sessid):
        return bool(self.redis.zscore(self.sockets_key, sessid))

    def load_socket(self, socket):
        """Reads from Redis and sets any internal state of the socket that must 
        be shared between all sockets in the same session.
        """
        socket.hits = self.redis.hincrby(self.make_bucket_name("hits", socket.sessid), socket.sessid, 1)

        if not socket.connection_established:
            connected = self.redis.sismember(self.connected_key, socket.sessid)
            if connected:
                self.init_connection(socket, nosync=True)

        return socket

    def save_socket(self, sessid):
        """Stores into Redis any internal state that must be shared between all sockets in the same session.
        """
        return

    def init_connection(self, socket, *args, **kwargs):
        super(RedisSocketManager, self).init_connection(socket, *args, **kwargs)
        if not kwargs.get("nosync", False):
            self.redis.sadd(self.connected_key, socket.sessid)

    def activate_endpoint(self, sessid, endpoint):
        key = self.make_session_key(sessid, "endpoints")
        self.redis.sadd(key, endpoint)
        self.notify_socket(sessid, "endpoint_activated", endpoint=endpoint)

    def deactivate_endpoint(self, sessid, endpoint):
        key = self.make_session_key(sessid, "endpoints")
        ret = self.redis.srem(key, endpoint) > 0
開發者ID:ryesoft,項目名稱:gevent-socketio,代碼行數:70,代碼來源:socket_manager.py


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