14.分布式爬虫 Redis基础

本文详细介绍Redis的基础操作,包括安装、启动、基本命令使用,如set、get、mset、mget等,并通过实例展示哈希存储法的运用。同时,文章还介绍了如何使用Python的redis模块进行数据库连接与数据读写操作。
Redis基础
  1. docker attach 3ba4
  2. apt-get install redis-server
  3. 启动: /etc/init.d/redis-server restart
  4. 退出:exit
  5. 查看是否能ping通: redis-cli -h 127.0.0.1 -o 6379
Redis命令
  1. redis-cli -h 127.0.0.1 p 6379
  2. set hello 123456789 #以key-value 方式存储
  3. get hello
  4. strlen hello
  5. 批量设置: mset a 199 b450 c hello
  6. 批量获取: mget a c
  7. 哈希存储法: key-filed-value
  8. hset title name hello
  9. hget title name
  10. hset title sex boy
  11. hget title sex
  12. 批量设置: hmset title name abc id 890 sex boy
  13. key:title filed:name id sex value:abc 890 boy
  14. hget title id
  15. hgetall title
  16. hset url 123.com 1
  17. hget url 123.com #判断是否为1还是0
import redis
import pymysql

rconn = redis.Redis("172.17.0.8", "6379")
# key-filed-value
# url - str(i) - value    value=1/0
for i in range(100):
	rconn.hget('url', str(i))
	rconn.hset('url'. str(i), '1')
	url = "http://www.baidu"+str(i)+".com"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值