Python安装并操作redis实现流程详解
作者:py鱼 时间:2023-06-15 00:17:22
Redis
redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。
1、安装redis
yum install redis -y
或者
wget http://download.redis.io/releases/redis-3.0.6.tar.gz
tar xzf redis-3.0.6.tar.gz
cd redis-3.0.6
make
2、启动redis这里注意对配置文件修改打开注释,不然py客户端连不上
守护模式不开就no
指定配置文件进行启动
然后准备设置redis验证密码(不然py连接报错)
退出,重新登录redis
3、python操作redis
#!/usr/bin/env python
# -*- coding:utf8 -*-
import redis
r = redis.Redis(host='192.168.11.122',password='123123',port=6379)
r.set('foo', 'Bar')
print (r.get('foo'))
4、线程池操作redis
'''
redis-py 使用connection pool 来管理对一个redis server的所有连接,避免每次建立,释放连接的开销
默认 每个redis实例都会维护一个自己的链接池,然后作为参数redis,这样就可以实现多个redis 实例共享一个连接池
'''
import redis
pool = redis.ConnectionPool(host='192.168.11.122',password='123123',port=6379)
r = redis.Redis(connection_pool=pool)
r.set('name','Yu chao')
print(r.get('name'))
来源:https://www.cnblogs.com/pyyu/p/6964593.html
标签:python,安装,操作,redis
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server免费版的安装以及使用SQL Server Management Studio(SSMS)连接数据库的图文方法
2024-01-15 03:45:14
![](https://img.aspxhome.com/file/2023/5/122375_0s.png)
mysql 5.7以上版本安装配置方法图文教程(mysql 5.7.12\\mysql 5.7.13\\mysql 5.7.14)
2024-01-17 23:14:46
![](https://img.aspxhome.com/file/2023/0/103130_0s.png)
python3 实现自定义切片类为左闭右闭详情
2022-11-02 11:36:51
基于Python实现的恋爱对话小程序详解
2023-01-14 11:08:38
![](https://img.aspxhome.com/file/2023/8/134798_0s.png)
GO语言实现简单的目录复制功能
2024-04-26 17:21:39
![](https://img.aspxhome.com/file/2023/3/134243_0s.jpg)
浅谈信息可视化
2010-03-10 10:55:00
![](https://img.aspxhome.com/file/UploadPic/20103/10/01-20s.jpg)
CentOS 7.4下安装Oracle 11.2.0.4数据库的方法
2024-01-24 20:36:20
![](https://img.aspxhome.com/file/2023/0/69370_0s.jpg)
识别操作系统是不是vista的js代码
2013-10-20 19:08:25
tensorflow2.0如何实现cnn的图像识别
2022-05-01 21:19:58
![](https://img.aspxhome.com/file/2023/9/77809_0s.jpg)
python绘制箱型图
2022-10-11 21:33:20
![](https://img.aspxhome.com/file/2023/6/127736_0s.jpg)
Python文件操作的方法
2022-10-27 19:54:29
![](https://img.aspxhome.com/file/2023/8/107938_0s.jpg)
我要如何了解用户的需求
2007-08-26 17:19:00
![](https://img.aspxhome.com/file/uploadpic/20078/26/2007826172453430.jpg)
分布式爬虫scrapy-redis的实战踩坑记录
2022-03-02 02:13:24
![](https://img.aspxhome.com/file/2023/9/120969_0s.png)
URL编码“陷阱”
2008-03-04 16:57:00
ADO组件之插入数据记录
2008-10-08 12:21:00
十行Python代码实现文字识别功能
2024-01-01 14:55:09
![](https://img.aspxhome.com/file/2023/1/80611_0s.png)
Python实现光速定位并提取两个文件的不同之处
2023-11-01 10:42:25
![](https://img.aspxhome.com/file/2023/9/98899_0s.jpg)
在ASP.NET 2.0中操作数据之四十六:使用SqlDataSource控件检索数据
2023-07-04 14:31:37
![](https://img.aspxhome.com/file/2023/6/76346_0s.gif)
Python实现列表转换成字典数据结构的方法
2023-03-17 22:59:09
IE6实现min-width
2008-06-12 12:40:00