Redis Cluster for Scrapy.
Project description
本项目基于原项目 scrpy-redis
进行修改,修改内容如下:
添加了 Redis 哨兵连接支持
添加了 Redis 集群连接支持
添加了 Bloomfilter 去重
安装
pip install scrapy-redis-sentinel --user
配置示例
原版本 scrpy-redis 的所有配置都支持, 优先级:哨兵模式 > 集群模式 > 单机模式
# ----------------------------------------Bloomfilter 配置-------------------------------------
# 使用的哈希函数数,默认为 6
BLOOMFILTER_HASH_NUMBER = 6
# Bloomfilter 使用的 Redis 内存位,30 表示 2 ^ 30 = 128MB,默认为 30 (2 ^ 22 = 1MB 可去重 130W URL)
BLOOMFILTER_BIT = 30
# 是否开启去重调试模式 默认为 False 关闭
DUPEFILTER_DEBUG = False
# ----------------------------------------Redis 单机模式-------------------------------------
# Redis 单机地址
REDIS_HOST = "172.25.2.25"
REDIS_PORT = 6379
# REDIS 单机模式配置参数
REDIS_PARAMS = {
"password": "password",
"db": 0
}
# ----------------------------------------Redis 哨兵模式-------------------------------------
# Redis 哨兵地址
REDIS_SENTINELS = [
('172.25.2.25', 26379),
('172.25.2.26', 26379),
('172.25.2.27', 26379)
]
# REDIS_SENTINEL_PARAMS 哨兵模式配置参数。
REDIS_SENTINEL_PARAMS= {
"service_name":"mymaster",
"password": "password",
"db": 0
}
# ----------------------------------------Redis 集群模式-------------------------------------
# Redis 集群地址
REDIS_MASTER_NODES = [
{"host": "172.25.2.25", "port": "6379"},
{"host": "172.25.2.26", "port": "6379"},
{"host": "172.25.2.27", "port": "6379"},
]
# REDIS_CLUSTER_PARAMS 集群模式配置参数
REDIS_CLUSTER_PARAMS= {
"password": "password"
}
# ----------------------------------------Scrapy 其他参数-------------------------------------
# 在 redis 中保持 scrapy-redis 用到的各个队列,从而允许暂停和暂停后恢复,也就是不清理 redis queues
SCHEDULER_PERSIST = True
# 调度队列
SCHEDULER = "scrapy_redis_sentinel.scheduler.Scheduler"
# 去重
DUPEFILTER_CLASS = "scrapy_redis_sentinel.dupefilter.RFPDupeFilter"
# 指定排序爬取地址时使用的队列
# 默认的 按优先级排序( Scrapy 默认),由 sorted set 实现的一种非 FIFO、LIFO 方式。
# SCHEDULER_QUEUE_CLASS = 'scrapy_redis_sentinel.queue.SpiderPriorityQueue'
# 可选的 按先进先出排序(FIFO)
# SCHEDULER_QUEUE_CLASS = 'scrapy_redis_sentinel.queue.SpiderStack'
# 可选的 按后进先出排序(LIFO)
# SCHEDULER_QUEUE_CLASS = 'scrapy_redis_sentinel.queue.SpiderStack'
注:当使用集群时单机不生效
spiders 使用
修改 RedisSpider 引入方式
原版本 scrpy-redis 使用方式
from scrapy_redis.spiders import RedisSpider
class Spider(RedisSpider):
...
scrapy-redis-sentinel 使用方式
from scrapy_redis_sentinel.spiders import RedisSpider
class Spider(RedisSpider):
...
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for scrapy-redis-sentinel-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0c694ea886a69a115f39af3aed51f2212679cd9135ae20a4f0dd0aa48325102 |
|
MD5 | efa44f52f1e6adb057fadbd12b37cd46 |
|
BLAKE2b-256 | e7f34b9c3295cede3057ad3d5ef71f3ef65f66ab078959ce10a1652a951d6020 |