转载:http://blog.csdn.net/moxiaomomo/article/details/8965244
#1、安装
好吧,我承认我只会最简单的安装sudo apt-get install redis-server
python 支持包: (其实就一个文件,搞过来就能用)
sudo apt-get install python-redis
#2、配置
配置一下吧,默认配置文件在: “/etc/redis/redis.conf”
绑定ip:
“bind 127.0.0.1″ -> “bind 10.0.1.7″
将磁盘同步改为 不同步或每秒同步,一直同步的话太慢了:
“appendfsync always” -> “appendfsync no”
检查一下后台执行是否打开:
“daemonize yes”
或者其他你想设置的,例如:
连接超时时间 : “timeout 300″
运行级别: “loglevel notice” (个人认为默认的这个就挺好,非出现大异常,不用改为debug )
#3、使用
#! /usr/bin/env python
#coding=utf-8
import redis
print redis.__file__
# 连接,可选不同数据库
r = redis.Redis(host='10.0.1.7', port=6379, db=1)
# -------------------------------------------
# 看信息
info = r.info()
for key in info:
print "%s: %s" % (key, info[key])
# 查数据库大小
print '\ndbsize: %s' % r.dbsize()