python使用redis第一节、环境配置

简介: python使用redis第一节、环境配置

开发环境:【Win10】、【Redis3.2.100】

开发工具:【PyCharm Community Edition 2021.3.1】

导读:

本章节我们将为大家介绍 Python 如何操作 redis,redis 是一个 Key-Value 数据库,Value 支持 string(字符串),list(列表),set(集合),zset(有序集合),hash(哈希类型)等类型。

Redis服务需要保持在开启状态。

image.png

通过pip下载Redis需求包

pip install redis

我这是都安装过了。

image.png



创建测试类【demo1.py】


在项目上点击【鼠标右键】,依次选择【New】与【File】


image.png


输入类名


demo1.py

image.png


输入以下编码测试:


import redis
#字符串格式链接,地址是localhost,没有密码,端口号是3379
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
r.set('myKey', 'myTestValue')  # 设置 key 与 value
print(r['myKey'])   # 取出键 key 对应的值
print(r.get('myKey'))  # 取出键 key 对应的值
print(type(r.get('myKey')))  # 查看类型

效果如下。


image.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.png

image.png

相关文章
|
NoSQL Unix 网络安全
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
306 0
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
|
数据采集 存储 NoSQL
分布式爬虫去重:Python + Redis实现高效URL去重
分布式爬虫去重:Python + Redis实现高效URL去重
|
NoSQL Linux Redis
linux安装单机版redis详细步骤,及python连接redis案例
这篇文章提供了在Linux系统中安装单机版Redis的详细步骤,并展示了如何配置Redis为systemctl启动,以及使用Python连接Redis进行数据操作的案例。
719 3
|
消息中间件 存储 NoSQL
python 使用redis实现支持优先级的消息队列详细说明和代码
python 使用redis实现支持优先级的消息队列详细说明和代码
523 0
|
缓存 NoSQL 网络安全
【Azure Redis 缓存】 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connection reset by peer"
【Azure Redis 缓存】 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connection reset by peer"
571 0
|
缓存 监控 NoSQL
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
218 0
|
NoSQL 网络安全 Redis
用python安装redis并设置服务自启
用python安装redis并设置服务自启
503 0
|
NoSQL Redis 数据安全/隐私保护
python 连接redis的哨兵模式
python 连接redis的哨兵模式
1813 0
|
NoSQL Redis Python
|
NoSQL 测试技术 数据库

热门文章

最新文章

推荐镜像

更多