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

Python memcache._Host函数代码示例

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

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



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

示例1: _node_stats

 def _node_stats(host):
     """
     Returns a dict with information about a given memcache instance
     """
     host = memcache._Host(host)
     host.connect()
     host.send_cmd("stats")
     stats = {}
     while 1:
         line = host.readline().split(None, 2)
         if line[0] == "END":
             break
         _, key, value = line
         try:
             # Convert to native type, if possible
             value = int(value)
             if key == "uptime":
                 value = datetime.timedelta(seconds=value)
             elif key == "time":
                 value = datetime.datetime.fromtimestamp(value)
         except ValueError:
             pass
         stats[key] = value
     host.close_socket()
     return stats
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:25,代码来源:statistics.py


示例2: get_memcached_stats

def get_memcached_stats(server):
    if not memcache_installed:
        return {}
    host = memcache._Host(server)
    host.connect()
    host.send_cmd("stats")
    
    stats = {}
    
    while True:
        try:
            stat, key, value = host.readline().split(None, 2)
        except ValueError:
            break
        try:
            # Convert to native type, if possible
            value = int(value)
            if key == "uptime":
                value = datetime.timedelta(seconds=value)
            elif key == "time":
                value = datetime.datetime.fromtimestamp(value)
        except ValueError:
            pass
        stats[key] = value

    host.close_socket()
    
    try:
        stats['hit_rate'] = 100 * stats['get_hits'] / stats['cmd_get']
    except ZeroDivisionError:
        stats['hit_rate'] = stats['get_hits']
    
    return stats
开发者ID:Anmol2307,项目名称:oneanddone,代码行数:33,代码来源:util.py


示例3: add_server

    def add_server(self, server):
        """ Adds a host at runtime to client
        """

        # Uncomment this to protect the Client from adding a server in case
        # there's no reliable consistent hash algorithm such as MODULO
        """
        if not self.consistent_hash_manager:
            raise Exception("The current consistent hash algorithm (\"%s\") is"
                            " not reliable for adding a new server"
                            "" % self.hash_algorithm)
        """

        # Create a new host entry
        server = memcache._Host(
            server, self.debug, dead_retry=self.dead_retry,
            socket_timeout=self.socket_timeout,
            flush_on_reconnect=self.flush_on_reconnect
        )
        # Add this to our server choices
        self.servers.append(server)

        """This for statement will ensure that a server with a bigger weight
        will have more copies into the buckets increasing it's probability to
        be retrieved.
        """
        for i in range(server.weight):
            self.buckets.append(server)

        # Adds this node to the circle
        if self.consistent_hash_manager:
            self.consistent_hash_manager.add_node(server)
开发者ID:arshad104,项目名称:my-python-work,代码行数:32,代码来源:new_memcached.py


示例4: _query_memcache_server

def _query_memcache_server(location):
    try:
        host = memcache._Host(location)
        host.connect()
        host.send_cmd("stats")
        
        stats = MemcachedStats()
        
        while True:
            line = host.readline().split(None, 2)
            if line[0] == "END":
                break
            stat, key, value = line
            try:
                value = int(value)
                if key == "uptime":
                    value = timedelta(seconds=value)
                elif key == "time":
                    value = datetime.fromtimestamp(value)
            except ValueError:
                pass
            
            setattr(stats, key, value)
        
        host.close_socket()
        
        return stats
    except Exception:
        return None
开发者ID:ahammouda3,项目名称:djpclient,代码行数:29,代码来源:memory.py


示例5: view

def view(request):
    """
    Draw up a horrible little page shewing current memcache stats. 404s if memcache isn't installed.
    """
    
    try:
        import memcache
    except ImportError:
        raise http.Http404
    
    if not (request.user.is_authenticated() and
            request.user.is_staff):
        raise http.Http404
    
    # get first memcached URI
    m = re.match(
        "memcached://([.\w]+:\d+)", settings.CACHE_BACKEND
    )
    if not m:
        raise http.Http404
    
    host = memcache._Host(m.group(1))
    host.connect()
    host.send_cmd("stats")
    
    class Stats:
        pass
    
    stats = Stats()
    
    while 1:
        line = host.readline().split(None, 2)
        if line[0] == "END":
            break
        stat, key, value = line
        try:
            # convert to native type, if possible
            value = int(value)
            if key == "uptime":
                value = datetime.timedelta(seconds=value)
            elif key == "time":
                value = datetime.datetime.fromtimestamp(value)
        except ValueError:
            pass
        setattr(stats, key, value)
    
    host.close_socket()
    
    hit_rate = 0
    if stats.cmd_get > 0:
        hit_rate = 100 * stats.get_hits / stats.cmd_get
    
    return render_to_response(
        'memcached_status.html', dict(
            stats=stats,
            hit_rate=hit_rate,
            time=datetime.datetime.now(), # server time
        ))
开发者ID:0sn,项目名称:nr_utils,代码行数:58,代码来源:mstat.py


示例6: cache_view

def cache_view(request):
    """
    Tries to import memcache, fails out if it can't and raises a 404. Also
    raises a 404 in the case of unauthenticated users, or memcache not
    being used. Graciously borrowed from:
    http://effbot.org/zone/django-memcached-view.htm
    """
    try:
        import memcache
    except ImportError:
        raise http.Http404

    if not (request.user.is_authenticated() and
            request.user.is_staff):
        raise http.Http404

    # get first memcached URI
    m = re.match(
        "memcached://([.\w]+:\d+)", settings.CACHE_BACKEND
    )
    if not m:
        raise http.Http404

    host = memcache._Host(m.group(1))
    host.connect()
    host.send_cmd("stats")

    class Stats:
        pass

    stats = Stats()

    while 1:
        line = host.readline().split(None, 2)
        if line[0] == "END":
            break
        stat, key, value = line
        try:
            # convert to native type, if possible
            value = int(value)
            if key == "uptime":
                value = datetime.timedelta(seconds=value)
            elif key == "time":
                value = datetime.datetime.fromtimestamp(value)
        except ValueError:
            pass
        setattr(stats, key, value)

    host.close_socket()

    return render_to_response(
        'memcached_status.html', dict(
            stats=stats,
            hit_rate=100 * stats.get_hits / stats.cmd_get,
            time=datetime.datetime.now(), # server time
        ))
开发者ID:RafeHatfield,项目名称:django-yaba,代码行数:56,代码来源:views.py


示例7: memcache_showkeys

def memcache_showkeys(request):
    """
    Displays all the keys and the size for the memcache server IP entered, takes by default 127.0.0.1:11211.
    Requires user login with a staff status set true.
    """
    
    if not (request.user.is_authenticated() and request.user.is_staff):
        raise http.Http404

    if request.method == "POST":
        try:
            import memcache
        except ImportError:
            raise http.Http404

        connection_string = '127.0.0.1:11211'

        host = memcache._Host(connection_string)
        host.connect()

        #getting all keys and size
        keyno_dict = {}
        host.send_cmd("stats items")
        while 1:
            line = host.readline().split(None, 2)
            if line[0] == "END":
                break

            if 'number' in line[1]:
                keyno = line[1].split(':')[1]
                item_size = line[2]
                keyno_dict[keyno] = item_size

        key_size_dict = {}
        for x,y in keyno_dict.items():
            cmd = 'stats cachedump ' + x +' '+ y
            host.send_cmd(cmd)
            while 1:
                temp = host.readline().split(None, 2)
                if temp[0] == "END":
                    break
                keyname = temp[1]
                keysize = temp[2].split()[0].replace('[','')
                try:
                    key_size_dict[keyname] = int(keysize)
                except:
                    key_size_dict[keyname] = 0

        host.close_socket()
        import operator
        soted_key_value_dict =sorted(key_size_dict.iteritems(), key=operator.itemgetter(1))

        return render_to_response('show_keys.html', locals(), context_instance = RequestContext(request) )
    else:
        return HttpResponseRedirect(reverse(memcache_home))
开发者ID:pathakamit88,项目名称:memcacheinfo,代码行数:55,代码来源:views.py


示例8: memcached_status

def memcached_status(request):
    # http://effbot.org/zone/django-memcached-view.htm
    try:
        import memcache
    except ImportError:
        raise Http404

    #if not (request.user.is_authenticated() and
    #        request.user.is_staff):
    #    raise Http404

    # get first memcached URI
    m = re.match(
        "([.\w]+:\d+)", settings.CACHES['default']['LOCATION'])
    if not m:
        raise Http404

    host = memcache._Host(m.group(1))
    host.connect()
    host.send_cmd("stats")

    class Stats:
        pass

    stats = Stats()

    while 1:
        line = host.readline().split(None, 2)
        if line[0] == "END":
            break
        stat, key, value = line
        try:
            # convert to native type, if possible
            value = int(value)
            if key == "uptime":
                value = datetime.timedelta(seconds=value)
            elif key == "time":
                value = datetime.datetime.fromtimestamp(value)
        except ValueError:
            pass
        setattr(stats, key, value)

    host.close_socket()

    try:
        hit_rate = 100 * stats.get_hits / stats.cmd_get
    except:
        hit_rate = 0

    return render_to_response(
        'cache/memcache_status.html', dict(
            stats=stats,
            hit_rate=hit_rate,
            time=datetime.datetime.now(), # server time
    ))
开发者ID:morezane,项目名称:django-calcifer-apps,代码行数:55,代码来源:views.py


示例9: cache_status

def cache_status(request, ):
    from django import http
    from django.shortcuts import render_to_response
    from django.conf import settings
    import datetime, re

    try:
        import memcache
    except ImportError:
        raise http.Http404

    if not (request.user.is_authenticated() and
            request.user.is_staff):
        raise http.Http404

    # get first memcached URI
    m = re.match(
        "memcached://([.\w]+:\d+)", settings.CACHE_BACKEND
    )
    if not m:
        raise http.Http404

    host = memcache._Host(m.group(1))
    host.connect()
    host.send_cmd("stats")

    class Stats:
        pass

    stats = Stats()

    while 1:
        line = host.readline().split(None, 2)
        if line[0] == "END":
            break
        stat, key, value = line
        try:
            # convert to native type, if possible
            value = int(value)
            if key == "uptime":
                value = datetime.timedelta(seconds=value)
            elif key == "time":
                value = datetime.datetime.fromtimestamp(value)
        except ValueError:
            pass
        setattr(stats, key, value)

    host.close_socket()

    return render_to_response(
        'memcached_status.html', dict(
            stats=stats,
            hit_rate=100 * stats.get_hits / stats.cmd_get,
            time=datetime.datetime.now(), # server time
        ))
开发者ID:jwineinger,项目名称:speedyreferrals,代码行数:55,代码来源:views.py


示例10: server_list

def server_list(request):
    template = 'status.html'
    try:
        import memcache
    except:
        raise Http404
    stats = {}
    cache_servers = {}
    dict_vars = {}
    servers = None
    # It assumes that you're using a right configuration
    try:
        servers = settings.CACHES['default']['LOCATION']
    except:
        return render_to_response(template, dict_vars, RequestContext(request))
    for server in servers:
        host = memcache._Host(server)
        host.connect()
        if host == 0:
            raise Http404
        try:
            host.send_cmd("stats")
        except:
            break
        while True:
            line = host.readline().split(None)
            if line[0] == "END":
                break
            try:
                val = int(line[2])
                if line[1] == "uptime":
                    value = datetime.timedelta(seconds=val)
                elif line[1] == "time":
                    value = datetime.datetime.fromtimestamp(val)
            except Exception:
                pass
            stats[line[1]] = line[2]
        stats['hit_rate'] = 0
        if int(stats['cmd_get']) != 0:
            stats['hit_rate'] = 100 * int(stats['get_hits']) / int(stats['cmd_get'])
        stats['right_now'] = datetime.datetime.now()

        limit_maxbytes = int(stats['bytes'])
        if int(stats['limit_maxbytes']) > 0:
            limit_maxbytes = int(stats['limit_maxbytes'])
        stats['full'] = (100 * int(stats['bytes']) / limit_maxbytes)
        # Add info. for this host to list
        cache_servers[server] = stats
        # Close connection
        host.close_socket()
    dict_vars['servers'] = cache_servers

    return render_to_response(template, dict_vars, RequestContext(request))
开发者ID:bsnux,项目名称:django-memcached-status,代码行数:53,代码来源:views.py


示例11: add_server

 def add_server(self, server):
     """ Adds a host at runtime to client"""
     # Create a new host entry
     server = memcache._Host(
         server, self.debug, dead_retry=self.dead_retry,
         socket_timeout=self.socket_timeout,
         flush_on_reconnect=self.flush_on_reconnect
     )
     # Add this to our server choices
     self.servers.append(server)
     # Update our buckets
     self.buckets.append(server)
     self.consistent_hash.add_machine(server,len(self.servers)-1)
开发者ID:excelsior43,项目名称:Consistent-Hashing-Algorithm,代码行数:13,代码来源:mamcache_client.py


示例12: view

def view(request):
    try:
        import memcache
    except ImportError:
        raise http.Http404
    
    # get first memcached URI
    m = re.match(
        "memcached://([.\w]+:\d+)", settings.CACHE_BACKEND
    )
    if not m:
        #raise http.Http404
        return HttpResponse("No Memcached Server 2")
    
    host = memcache._Host(m.group(1))
    host.connect()
    host.send_cmd("stats")
    
    class Stats:
        pass
    
    stats = Stats()
    
    while 1:
        line = host.readline().split(None, 2)
        if line[0] == "END":
            break
        stat, key, value = line
        try:
            # convert to native type, if possible
            value = int(value)
            if key == "uptime":
                value = datetime.timedelta(seconds=value)
            elif key == "time":
                value = datetime.datetime.fromtimestamp(value)
        except ValueError:
            pass
        setattr(stats, key, value)

    host.close_socket()
    if stats.cmd_get == 0:
        hit_rate = 'na'
    else:
        hit_rate = 100 * stats.get_hits / stats.cmd_get
    return render_to_response(
        'memcached_status.html', dict(
            stats=stats,
            hit_rate=hit_rate,
            time=datetime.datetime.now(), # server time
        ))
开发者ID:cccarey,项目名称:demisauce,代码行数:50,代码来源:memcached_status.py


示例13: cache_status

def cache_status(request):
    """
    Fetch memcache status and display it.
    Taken and modified from: http://effbot.org/zone/django-memcached-view.htm
    
    """
    try:
        import memcache
    except ImportError:
        return direct_to_template(request, 'memcachedstatus/cache_status.html', {'error': _(u'Memcached library not installed')})

    if not MEMCACHE:
        return direct_to_template(request, 'memcachedstatus/cache_status.html', {'error': _(u'No memcached configured')})

    host = memcache._Host(MEMCACHE.group(1))
    host.connect()
    try:
        host.send_cmd("stats")
    except AttributeError:
        return direct_to_template(request, 'memcachedstatus/cache_status.html', {'error': _(u'Memcached not running')})

    class Stats:
        pass

    stats = Stats()

    while 1:
        line = host.readline().split(None, 2)
        if line[0] == "END":
            break
        stat, key, value = line
        try:
            # convert to native type, if possible
            value = int(value)
            if key == "uptime":
                value = datetime.timedelta(seconds=value)
            elif key == "time":
                value = datetime.datetime.fromtimestamp(value)
        except ValueError:
            pass
        setattr(stats, key, value)

    host.close_socket()
    if stats.cmd_get != 0:
        context = {'stats': stats, 
               'hit_rate': 100 * stats.get_hits / stats.cmd_get,}
    else:
        context = {'stats': stats}
               
    return direct_to_template(request, 'memcachedstatus/cache_status.html', context)
开发者ID:arneb,项目名称:django-memcachedstatus,代码行数:50,代码来源:views.py


示例14: add_server

 def add_server(self, server):
     """ Adds a host at runtime to client
     """
     # Create a new host entry
     server = memcache._Host(
         server, self.debug, dead_retry=self.dead_retry,
         socket_timeout=self.socket_timeout,
         flush_on_reconnect=self.flush_on_reconnect
     )
     # Add this to our server choices 
     self.servers.append(server)
     self.buckets.append(server)
     self.mc_ring.servers.append(server)
     self.mc_ring.buckets.append(server)
开发者ID:robeferre,项目名称:dubizzle_test,代码行数:14,代码来源:new__memcached.py


示例15: memcached_status

def memcached_status(request):
    try:
        import memcache
    except ImportError:
        return HttpResponseRedirect("/")

    if not (request.user.is_authenticated() and
            request.user.is_staff):
        return HttpResponseRedirect("/")

    # get first memcached URI
    m = re.match(
        "memcached://([.\w]+:\d+)", settings.CACHE_BACKEND
    )
    if not m:
        return HttpResponseRedirect("/")

    host = memcache._Host(m.group(1))
    host.connect()
    host.send_cmd("stats")

    class Stats:
        pass

    stats = Stats()

    while 1:
        line = host.readline().split(None, 2)
        if line[0] == "END":
            break
        stat, key, value = line
        try:
            # convert to native type, if possible
            value = int(value)
            if key == "uptime":
                value = datetime.timedelta(seconds=value)
            elif key == "time":
                value = datetime.datetime.fromtimestamp(value)
        except ValueError:
            pass
        setattr(stats, key, value)

    host.close_socket()
    
    return render_to_response(
        'webview/memcached_status.html', dict(
            stats=stats, 
            hit_rate=100 * stats.get_hits / stats.cmd_get,
            time=datetime.datetime.now(), # server time
        ), context_instance=RequestContext(request))
开发者ID:GitLaboratory,项目名称:demovibes,代码行数:50,代码来源:views.py


示例16: memcache_status

def memcache_status(request):
    """
    display memcache server info
    based on: http://effbot.org/zone/django-memcached-view.htm
    """
    try:
        import memcache
    except ImportError:
        raise http.Http404

    stats = {}

    # get all memcached URIs
    m = re.match(
        "memcached://([^/]*)/?$", settings.CACHE_BACKEND
    )
    if m:
        servers = m.group(1).split(';')
        if not servers:
            raise http.Http404

        for server in servers:
            host = memcache._Host(server)
            host.connect()
            host.send_cmd("stats")

            stats[server] = {}
            while True:
                line = host.readline().split(None, 2)
                if line[0] == "END":
                    break
                stat, key, value = line
                try:
                    # convert to native type, if possible
                    value = int(value)
                    if key == "uptime":
                        value = datetime.timedelta(seconds=value)
                    elif key == "time":
                        value = datetime.datetime.fromtimestamp(value)
                except ValueError:
                    pass
                stats[server][key] = value

            stats[server]['hit_rate'] = (100 * stats[server]['get_hits'] /
                                         stats[server]['cmd_get'])
            host.close_socket()

    return render_to_response('stats/memcached_status.html', {'stats': stats},
                              context_instance=RequestContext(request))
开发者ID:Callek,项目名称:tuxedo,代码行数:49,代码来源:views.py


示例17: server_statics

def server_statics(request):

    if not (request.user.is_authenticated() and request.user.is_staff):
        raise http.Http404

    if request.method == 'POST':
        try:
            import memcache
        except ImportError:
            raise http.Http404

        connection_string = '127.0.0.1:11211'

        host = memcache._Host(connection_string)
        host.connect()
        host.send_cmd("stats")

        class Stats:
            pass
        stats = Stats()

        while 1:
            line = host.readline().split(None, 2)
            if line[0] == "END":
                break
            stat, key, value = line
            try:
                # convert to native type, if possible
                value = int(value)
                if key == "uptime":
                    value = datetime.timedelta(seconds=value)
                elif key == "time":
                    value = datetime.datetime.fromtimestamp(value)
            except ValueError:
                pass
            setattr(stats, key, value)

        try:
            stats=stats
            hit_rate=100 * stats.get_hits / stats.cmd_get
            time=datetime.datetime.now()
            host.close_socket()
        except :
            host.close_socket()
            return HttpResponseRedirect(reverse('memcache_home'))

        return render_to_response('server_status.html', locals(), context_instance = RequestContext(request) )
    else:
        return HttpResponseRedirect(reverse(memcache_home))
开发者ID:pathakamit88,项目名称:memcacheinfo,代码行数:49,代码来源:views.py


示例18: memcached_status

def memcached_status(request):
    try:
        import memcache
    except ImportError:
        raise Http404

    if not request.user.is_authenticated() and request.user.is_superuser:
        raise Http404

    # get first memcached URI
    m = re.match("memcached://([.\w]+:\d+)", settings.CACHE_BACKEND)
    if not m:
        raise Http404

    host = memcache._Host(m.group(1))
    host.connect()
    host.send_cmd("stats")

    class Stats:
        pass

    stats = Stats()

    while 1:
        line = host.readline().split(None, 2)
        if line[0] == "END":
            break
        stat, key, value = line
        try:
            # convert to native type, if possible
            value = int(value)
            if key == "uptime":
                value = datetime.timedelta(seconds=value)
            elif key == "time":
                value = datetime.datetime.fromtimestamp(value)
        except ValueError:
            pass
        setattr(stats, key, value)

    host.close_socket()

    return render_to_response(
        "base/memcached_status.html",
        {
            "stats": stats,
            "hit_rate": 100 * stats.get_hits / stats.cmd_get,
            "time": datetime.datetime.now(),  # server time
        },
    )
开发者ID:simonqiang,项目名称:tendenci,代码行数:49,代码来源:views.py


示例19: add_server

 def add_server(self, server):
     """ Adds a host at runtime to client
     """
     server_tmp = server
     # Create a new host entry
     server = memcache._Host(
         server, self.debug, dead_retry=self.dead_retry,
         socket_timeout=self.socket_timeout,
         flush_on_reconnect=self.flush_on_reconnect
     )
     # Add this to our server choices
     self.servers.append(server)
     self.buckets.append(server)
     # Adds this node to the circle
     self.consistent_hash.add_nodes([server_tmp])
开发者ID:oreza,项目名称:memcached_ketama,代码行数:15,代码来源:memcached_ketama.py


示例20: get_stats

def get_stats():
    host = memcache._Host('127.0.0.1:11211')
    host.connect()
    host.send_cmd('stats')
    stats = {}
    while 1:
        line = host.readline().split(None, 2)
        if line[0] == "END": break
        stat, key, value = line
        try:
            value = int(value)
        except ValueError:
            pass
        stats[key] = value
    host.close_socket()

    return stats
开发者ID:lacunoc,项目名称:igmonplugins,代码行数:17,代码来源:check_memcached_misses.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python memcache.Client类代码示例发布时间:2022-05-27
下一篇:
Python membership.Membership类代码示例发布时间: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