Redis有序集合的应用和实践
在对接第三方代理IP的过程中,如何优雅的实现,下面是两种方案
# zset
# 时间戳+信息
zadd proxy 1692002577 {"proxy_ip":"183.151.125.155","server":"183.151.125.155:14509","area":"浙江省丽水市","isp":"电信","deadline":"2023-08-14 16:42:50"}
# 取出大于 timestamp 的代理IP
zrangebyscore myzset (1691998414 +inf
# 时间复杂度
综合以上,ZRANGEBYSCORE 命令的时间复杂度为 O(log N + M)。
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# hash
# hset myhash field1 value1
hset proxy 183.151.125.155:14509 {"proxy_ip":"183.151.125.155","server":"183.151.125.155:14509","area":"浙江省丽水市","isp":"电信","deadline":"2023-08-14 16:42:50"}
# 设置哈希过期时间(单位为秒)
expire myhash 60
expire proxy 60
# 取值
hkeys proxy
183.151.125.155:14509
hvals porxy
{"proxy_ip":"183.151.125.155","server":"183.151.125.155:14509","area":"浙江省丽水市","isp":"电信","deadline":"2023-08-14 16:42:50"}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
上次更新: 2023-08-21 15:06:24