章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • python

    • python基础

      • python基础知识
      • python基础较难的15个知识点
    • FastAPI

    • python每日练习脚本

    • python3给防火墙添加放行
    • python生成部署脚本
    • python将多个文件内容输出到一个文件中
    • 使用 Aligo 定时备份服务器文件
    • python监控日志文件并发送钉钉告警
    • python监控数据库脚本并发送钉钉告警
    • 使用python编写自动化发布脚本
    • 查询redis列表某个元素
    • centos7安装python3
    • python环境管理工具介绍
    • conda安装和镜像源配置
    • pip更换国内源
    • python爬虫
    • python环境启动服务报错缺少glibc库版本
    • 监控目录或文件变化
    • 批量更改文件
    • python引用数据库
  • shell

  • go

  • 编程
  • python
章工运维
2024-07-10

查询redis列表某个元素

# redis单节点查询列表元素

import redis

# 连接到 Redis 服务器(假设使用密码)
r = redis.Redis(
    host='localhost', 
    port=6379, 
    db=0, 
    password='your_password'   # 需要验证的密码
)

# 列表键
key = 'mylist'

# 需要检查的元素
element_to_check = '20223453424324'

# 获取整个列表
values = r.lrange(key, 0, -1)

# 检查元素是否存在
exists = element_to_check.encode() in values

if exists:
    print(f"元素 {element_to_check} 存在于列表中。")
else:
    print(f"元素 {element_to_check} 不存在于列表中。")

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

# redis cluster查询列表某个元素

from rediscluster import RedisCluster

# 连接到 Redis 集群
startup_nodes = [{"host": "localhost", "port": "6379"}]
rc = RedisCluster(startup_nodes=startup_nodes, decode_responses=True, password='your_password')

# 列表键
key = 'mylist'

# 需要检查的元素
element_to_check = '20223453424324'

# 获取整个列表
values = rc.lrange(key, 0, -1)

# 检查元素是否存在
exists = element_to_check in values

if exists:
    print(f"元素 {element_to_check} 存在于列表中。")
else:
    print(f"元素 {element_to_check} 不存在于列表中。")

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
微信 支付宝
上次更新: 2024/07/12, 14:35:39

← 使用python编写自动化发布脚本 centos7安装python3→

最近更新
01
shell脚本模块集合
05-13
02
生活小技巧(认知版)
04-29
03
生活小技巧(防骗版)
04-29
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式