作家
登录

用Python写一个NoSQL数据库

作者: 来源: 2017-05-18 13:03:15 阅读 我要评论

  •             value = str(value) 
  •     else
  •         value = None 
  •     return command, key, value  
  • 这里我们可以看到产生潦攀类型转换 (type conversion). 如不雅欲望值是一个 list, 我们可以经由过程对 string 调用 str.split(',') 来获得我们想要的值。 对于 int, 我们可以简单地应用参数为 string 的 int() 即可。 对于字符串与 str() 也是同样的事理。

    Command Handlers

    下面是敕令处理器 (command handler) 的代码. 它们都十分直不雅,易于懂得。 留意到固然有很多的缺点检查, 然则也并不是面面俱到, 十分复杂。 在你浏览的过程中,如不雅发明有任何缺点请移步 这里 进行评论辩论.

    1. def update_stats(command, success): 
    2.     """Update the STATS dict with info about if executing *command* was a 
    3.     *success*""
    4.     if success: 
    5.         STATS[command]['success'] += 1 
    6.     else
    7.         STATS[command]['error'] += 1 
    8.  
    9.  
    10. def handle_put(key, value): 
    11.     """Return a tuple containing True and the message to send back to the 
    12.     client.""
    13.     DATA[key] = value 
    14.     return (True'key [{}] set to [{}]'.format(key, value)) 
    15.  
    16.  
    17. def handle_get(key): 
    18.     """Return a tuple containing True if the key exists and the message to send 
    19.     back to the client""
    20.     if key not in DATA: 
    21.         return (False'Error: Key [{}] not found'.format(key)) 
    22.     else
    23.         return

        推荐阅读

        交通银行信息技术管理部副总经理张漫丽:交通银行“大数据+人工智能”应用研究

      大年夜数据隐含着巨大年夜的社会、经济、科研价值,已引起了各行各业的高度看重。如不雅能经由过程人工智能技巧有效地组织和应用大年夜数据,将对社会经济和科学研究成长产生巨大年夜的推>>>详细阅读


      本文标题:用Python写一个NoSQL数据库

      地址:http://www.17bianji.com/lsqh/35303.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)