zoukankan      html  css  js  c++  java
  • Python redis 简单介绍

    Python redis 简单介绍

    1、安装

    终端输入:

    pip(or)pip3.6 install redis

    安装成功

     2、哈哈,发现我并没有redis服务可以访问,所以到这里,在本机安装了redis 服务

    安装方法:http://www.runoob.com/redis/redis-install.html

    并完成配置。

    3、导入redis及操作

    # FileName : pyRedis_practice.py
    # Author   : Adil
    # DateTime : 2018/7/26 16:33
    # SoftWare : PyCharm
    
    # redis  练习
    
    # 导入 redis
    import redis
    
    # 创建连接
    
    #  严格连接方式
    r = redis.StrictRedis(host='127.0.0.1',port=6379)
    # python 化连接
    pr = redis.Redis(host='127.0.0.1',port=6379)
    
    # StrictRedis用于实现大部分官方的命令,并使用官方的语法和命令
    # Redis与StrictRedis的区别是:Redis是StrictRedis的子类,用于向前兼容旧版本的redis-py,并且这个连接方式是更加"python化"的
    
    
    # 连接池
    
    # 为了节省资源,减少多次连接损耗,连接池的作用相当于总揽多个客户端与服务端的连接,
    # 当新客户端需要连接时,只需要到连接池获取一个连接即可,实际上只是一个连接共享给多个客户端。
    
    pool = redis.ConnectionPool(host='localhost',port=6379,decode_responses=True)
    
    r1 = redis.Redis(connection_pool=pool)
    
    r2 = redis.Redis(connection_pool=pool)
    
    r.set('a','1')
    print(r.get('a'))
    
    print(r.client_list())
    
    print(pr.client_list())
    
    print(r1.client_list())
    
    print(r2.client_list())
    
    # r1  r2 的 的连接id 是一样的,说明他们是一个客户端连接
  • 相关阅读:
    Flex弹性布局在移动设备上的应用
    移动端页面开发问题总结
    js中的this关键字详解
    require.js 入门学习 (share)
    jQuery自定义滚动条样式插件mCustomScrollbar
    js中继承的几种用法总结(apply,call,prototype)
    js正则表达式
    js判断访问来源
    javascript 函数及作用域总结介绍
    javascript深入理解js闭包
  • 原文地址:https://www.cnblogs.com/BlueSkyyj/p/9372978.html
Copyright © 2011-2022 走看看