Redis的Python客户端redis-py
1. 安装
1
|
sudo easy_install redis |
1
2
3
|
2. Parser安装
1
|
easy_install hiredis |
2. 使用
1
2
3
4
5
6
7
|
import redis r = redis.StrictRedis(host = '127.0.0.1' , port = 9212 ) r. set ( 'foo' , 'hello' ) r.rpush( 'mylist' , 'one' ) print r.get( 'foo' ) print r.rpop( 'mylist' ) |
1
2
3
4
5
6
7
8
|
import redis pool = redis.ConnectionPool(host = '127.0.0.1' , port = 9212 ) r = redis.Redis(connection_pool = pool) r. set ( 'one' , 'first' ) r. set ( 'two' , 'second' ) print r.get( 'one' ) print r.get( 'two' ) |
redis pipeline机制,可以在一次请求中执行多个命令,这样避免了多次的往返时延。
1
2
3
4
5
6
7
8
9
10
|
import redis pool = redis.ConnectionPool(host = '127.0.0.1' , port = 9212 ) r = redis.Redis(connection_pool = pool) pipe = r.pipeline() pipe. set ( 'one' , 'first' ) pipe. set ( 'two' , 'second' ) pipe.execute() pipe. set ( 'one' . 'first' ).rpush( 'list' , 'hello' ).rpush( 'list' , 'world' ).execute() |
redis-py默认在一次pipeline中的操作是原子的,要改变这种方式,可以传入transaction=False,
1
|
pipe = r.pipeline(transaction = False ) |
Redis的Python客户端redis-py的更多相关文章
- Redis的Python客户端redis-py的初步使用
1. Redis的安装 sudo pip install redis sudo pip install hiredis Parser可以控制如何解析redis响应的内容.redis-py包含两个Par ...
- Redis的Python客户端redis-py说明文档(转)
add by zhj: 对Publish / Subscribe,LUA Scripting,Sentinel support,Scan Iterators等部分没有翻译,需要的用户参见英文原文吧.另 ...
- Redis之Python 使用 Redis
Python 使用 Redis 参考文档: http://redis.cn/clients.html#python https://github.com/andymccurdy/redis-py 安装 ...
- Django day 34 过滤课程,登录,redis,python操作redis
一:过滤课程, 二:登录 三:redis, 四:python操作redis
- Redis 以及 Python操作Redis
Redis Redis是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. Redis有以下特点: -- Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可 ...
- 安装 Redis的Python客户端redis-py
安装 redis-py 使用easy_install sudo easy_install redis 源码安装 git clone https://github.com/andymccurdy/red ...
- 八十九:redis之python操作redis
安装:pip install redis 连接 字符串操作 插入值 获取 删除值 列表操作,更多操作见源码 添加 获取 集合操作,更多操作见源码 哈希操作,更多操作见源码 事务操作:cache.pip ...
- Redis在python中的使用
一 简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted ...
- python与redis
1.什么是redis Redis 是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset ...
随机推荐
- Motion images compression and restoration based on computer vision
This technique should apply to both normal video (consequtive sequences of pictures of real world) a ...
- mysql数据向Redis快速导入
Redis协议 *<args><cr><lf> 参数个数 $<len><cr><lf> 第一个参数长度 <arg0> ...
- CDOJ 1431 不是图论 Label:Tarjan || Kosarajn
Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Description 给出一个nn个点, ...
- 原生js动画效果(源码解析)
在做页面中,多数情况下都会遇到页面上做动画效果,大部分都是用jquery来实现动画,今天正好看到一篇原生js实现动画效果的代码,特分享在此. 原文地址:http://www.it165.net/pro ...
- 通过Ajax post Json类型的数据到Controller
View function postSimpleData() { $.ajax({ type: "POST", url: "/Service/SimpleData&quo ...
- SDL实战,小游戏
http://www.cppblog.com/sandy/archive/2005/12/28/2219.html sdl1教学 http://kelvmiao.info/sdl-tutorial-c ...
- LBS基站数据解析接口
http://www.cellocation.com/interfac/#hybrid http://www.cellid.cn/ https://www.juhe.cn/docs/api/id/8
- C#中的接口
C#中的接口(转) 转自:http://www.cnblogs.com/zhenyulu/articles/377705.html 本文中所有图示纯为个人理解(参考了Assembly中元数据的存储方式 ...
- java实现MD5加密
mport java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Creat ...
- php date()获取的时间不对解决办法
因为php默认获取的是格林威治时间,与北京时间相差8小时. 我们要获取到北京时间有两个办法: 1.修改php.ini配置文件: 打开php.ini文件,一般在php配置根目录下,找到其中的 ;date ...