zoukankan      html  css  js  c++  java
  • 使用Python客户端(redis-py)连接Redis--华为云DCS for Redis使用经验

    使用Python连接Redis,需要先安装Python以及redis-py,以CentOS为例,介绍redis-py的客户端环境搭建。

    第0步:准备工作

    华为云上购买1台弹性云服务器ECS(我选了CentOS 6.3),一个分布式缓存实例(DCS for Redis),我选了个单机实例。

    注意ECS和缓存实例配置相同的VPC和安全组,确保网络互通。

    第1步:安装python和redis-py

    如果系统没有自带python,可以使用yum方式安装。

    yum install python

    下载并解压redis-py

    wget https://github.com/andymccurdy/redis-py/archive/master.zip;

    进入到解压目录后安装redis-py

    python setup.py install;

    安装后如此验证,不报错说明成功安装redis-py:

    [root@ecs-herucentos redis-py-master]# python
    Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import redis
    >>> 
    

      

    第2步:连接redis(缓存实例)

    命令行模式举例(也可以将命令写入python脚本中再执行):

    [root@ecs-herucentos redis-py-master]# python
    Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import redis
    >>> r = redis.StrictRedis(host='192.168.0.171', port=6379, password='******');
    >>> r.set('welcome','Hello, DCS for Redis!');
    True
    >>> print r.get('welcome');
    Hello, DCS for Redis!
    >>> exit();
    [root@ecs-herucentos redis-py-master]# 
    

      

  • 相关阅读:
    CSS position, z-index
    Js闭包函数
    .net 全局配置读取
    redis学习
    .net core websocket
    .net core 部署应用程序注意事项
    signalr网上学习资料
    Cocos Creator 中如果Node在"属性检查器"中active设置为false, 则 onLoad 不会执行
    SVN服务器搭建(一)
    IndentityServer4
  • 原文地址:https://www.cnblogs.com/husterindg/p/redis-py.html
Copyright © 2011-2022 走看看