1、Windows 下先安装 Redis 程序包;
下载.msi 的安装包
到目录下
启动命令
【停止服务】
redis-cli shutdown
redis-cli -p 6379 shutdown
redis-cli -p 8888 shutdown
【启动命令】
rides 对应目录下执行命令
redis-serve
#启动成功
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.12 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 6736
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[6736] 10 Aug 22:01:22.247 # Server started, Redis version 2.8.12
[6736] 10 Aug 22:01:22.248 * The server is now ready to accept connections on port 6379
Python 下 安装扩展包
pip install redis
#实例脚本
# encoding=utf-8
# 载入模块
import redis
# 链接redis数据库
r = redis.Redis(host='localhost', port=6379, db=0)
# 往redis中写数据
r.set('hello','world')
print(r.get('hello'))
r.set('Key', 'value')
# 查看对应的值
print 'Key', r.get('Key')
r['diaosi'] = 'yy'
r.set('xueba', 'xuexi')
r['xuezha'] = 'wan'
print (r.get('xuezha'))
# 查看数据库中有多少个key,多少条数据
print r.dbsize()
# 将数据保存到硬盘中(保存时阻塞)
r.save()
# 查看键值是否存在
print "是否存在结果为:",r.exists("doubi")
# 列出所有键值
print "列出所有键值",r.keys()
# 删除键值对应的数据
print r.delete('diaosi')
print r.delete('xuezha')
# 删除当前数据库所有数据
r.flushdb()