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

相关文章
|
7月前
|
数据采集 存储 NoSQL
分布式爬虫去重:Python + Redis实现高效URL去重
分布式爬虫去重:Python + Redis实现高效URL去重
|
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')
159 0
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
|
NoSQL Linux Redis
linux安装单机版redis详细步骤,及python连接redis案例
这篇文章提供了在Linux系统中安装单机版Redis的详细步骤,并展示了如何配置Redis为systemctl启动,以及使用Python连接Redis进行数据操作的案例。
412 3
|
消息中间件 存储 NoSQL
python 使用redis实现支持优先级的消息队列详细说明和代码
python 使用redis实现支持优先级的消息队列详细说明和代码
247 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"
283 0
|
缓存 监控 NoSQL
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
112 0
|
NoSQL 网络安全 Redis
用python安装redis并设置服务自启
用python安装redis并设置服务自启
218 0
|
NoSQL Redis Python
Redis与Python进行交互
安装包 安装Redis的有3种方式https://github.com/andymccurdy/redis-py 第一种:进⼊虚拟环境,联⽹安装包redis pip install redis 第二种:进⼊虚拟环境,联⽹安装包redis easy_install redis 第三种:到...
1657 0
|
7月前
|
缓存 NoSQL 关系型数据库
美团面试:MySQL有1000w数据,redis只存20w的数据,如何做 缓存 设计?
美团面试:MySQL有1000w数据,redis只存20w的数据,如何做 缓存 设计?
美团面试:MySQL有1000w数据,redis只存20w的数据,如何做 缓存 设计?
|
2月前
|
缓存 负载均衡 监控
135_负载均衡:Redis缓存 - 提高缓存命中率的配置与最佳实践
在现代大型语言模型(LLM)部署架构中,缓存系统扮演着至关重要的角色。随着LLM应用规模的不断扩大和用户需求的持续增长,如何构建高效、可靠的缓存架构成为系统性能优化的核心挑战。Redis作为业界领先的内存数据库,因其高性能、丰富的数据结构和灵活的配置选项,已成为LLM部署中首选的缓存解决方案。

推荐镜像

更多