python封装redis的api

开发环境:

 

      mac

      python

      redis

      pypi/redis    https://pypi.python.org/pypi/redis

 

步骤:

      1.

      安装运行主体redis 

      http://redis.io/

      目前最新版本是3.0.7

      

       2.

      安装pyi/redis

     验证redis的涵数功能

     

 

 

        3.

       安装django的restful_api 模块

        http://www.django-rest-framework.org/#installation

        

Requirements

REST framework requires the following:

  • Python (2.7, 3.2, 3.3, 3.4, 3.5)
  • Django (1.7+, 1.8, 1.9)

The following packages are optional:

Installation

Install using pip, including any optional packages you want...

pip install djangorestframework
pip install markdown       # Markdown support for the browsable API.
pip install django-filter  # Filtering support

...or clone the project from github.

git clone git@github.com:tomchristie/django-rest-framework.git

Add 'rest_framework' to your INSTALLED_APPS setting.

INSTALLED_APPS =(...'rest_framework',)

 

         代码部分:

        

          import redis

class pyRedis:
    def __init__(self):
        self.host = '127.0.0.1'
self.port = '6379'
self.db = 0
# self.c = redis.StrictRedis(host=self.host,port=self.port,db=self.db)
pool = redis.ConnectionPool(host=self.host,port=self.port,db=self.db)
        self.r = redis.Redis(connection_pool=pool)
        # self.c = redis.Redis(host=self.host,port=self.port,db=self.db)
def set_key(self,key,valuse):
        try:
            return  self.r.set(key,valuse)
        except Exception as e:
            print  e.message

    def get_key(self,key):
        try:
            return self.r.get(key)
        except Exception as e:
            print  e.message

 

    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值