首页 > 编程语言 > 详细

python封装redis的api

时间:2016-04-14 02:04:37      阅读:274      评论:0      收藏:0      [点我收藏+]

开发环境:

?

? ? ? mac

? ? ? python

? ? ? redis

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

?

步骤:

? ? ? 1.

? ? ? 安装运行主体redis?

? ? ??http://redis.io/

? ? ? 目前最新版本是3.0.7

? ? ??

? ? ? ?2.

? ? ? 安装pyi/redis

? ? ?验证redis的涵数功能

? ? ?
bubuko.com,布布扣
?

?

? ? ? ? 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

?

? ??

python封装redis的api

原文:http://hugoren.iteye.com/blog/2289980

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!