新聞中心
Redis ??? ?? ????

Redis? ????? ??? ??? ??? ???? NoSQL ????????. Redis? ??? ???? ???? ??? ?? ???? ????. ??? Redis?? ?? ??? ??? ? ??? ??? ? ??.
??? ??? Redis?? ??? ?? ??? ???? ??? ????. ? ???? Python ??? Redis ??? ???? ???? ???? ???? ??? ?? ???.
1. Redis ?? ????
Python ???? Redis ??? ???? ???? redis ??? ???? ??. ??? ???? ???? ??? ????.
“`python
pip install redis
???? Redis ??? ???? ??? ????.
```python
import redis
redis_client = redis.StrictRedis(host='', port=, db=, password='')
2. ?? ??? ?? ???? ????
Redis?? Redis ??? `scan_iter()` ??? ???? Redis ??????? ?? ??? ? ??. ? ??? Redis ??????? ?? ?? ?? ????. ???? ???? ???? ?? ????? ?????.
“`python
def delete_redis_data():
cursor = ‘0’
batch_size = 5000 #batch_size ?? ??? Redis ???? ?? ?? ?? (?? 50 ??? 100).
while cursor != 0:
cursor, keys = redis_client.scan(cursor=cursor, count=batch_size)
if keys:
redis_pipe = redis_client.pipeline()
for key in keys:
redis_pipe.delete(key)
redis_pipe.execute()
3. ?? ?? ????
?? `delete_redis_data()` ??? ???? ?? ??? ??? ? ??.
```python
if __name__ == "__mn__":
delete_redis_data()
4. ???
????? ???? ?????. Redis? ???? ?? `delete_redis_data()` ??? ?????.
“`python
redis_client.set(‘test_key1’, ‘test_value1’)
redis_client.set(‘test_key2’, ‘test_value2’)
delete_redis_data()
`delete_redis_data()` ??? ??? ? Redis ???????? ?? ?? ????? `test_key1`? `test_key2`? ????.
??
Redis?? ??? ?? ??? ??? ? Python ??? ??? ? ??. Redis ??? `scan_iter()` ??? ???? Redis ??????? ????, Python tube ??? ???? Redis ???? ?? ??? ? ??. ?? ?? Redis ???? ???? ????? ? ??.
成都服務(wù)器租用選創(chuàng)新互聯(lián),先試用再開通。
創(chuàng)新互聯(lián)(www.cdcxhl.com)提供簡單好用,價格厚道的香港/美國云服務(wù)器和獨立服務(wù)器。物理服務(wù)器托管租用:四川成都、綿陽、重慶、貴陽機房服務(wù)器托管租用。
本文標(biāo)題:Redis ??? ?? ????(redis遠程批量刪除)
URL標(biāo)題:http://m.fisionsoft.com.cn/article/dhopeeh.html


咨詢
建站咨詢
