-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_redis.py
131 lines (94 loc) · 2.4 KB
/
test_redis.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#coding:utf8
#! /bin/python
import cPickle as pickle
from redis_inc import RedisConnection, RedisQueueConnection
def flist(fname):
return open(fname).read().strip().split('\n')
def f(fname):
return open(fname)
def test():
runque = RedisQueueConnection('robots').conn
#########runque.flushdb()
size = runque.qsize()
item = runque.get()
runque.put(item)
print pickle.loads(item)
print size
return
raw_input('cofrim')
s = flist('urlstogetrobots.txt')
for url in s:
runque.put(url)
print runque.qsize()
def run():
runque = RedisQueueConnection('running').conn
#########runque.flushdb()
size = runque.qsize()
print size
raw_input('flush runing')
runque.flushdb()
def rmdb(test):
runque = RedisQueueConnection(test).conn
print runque.qsize()
raw_input('yes?')
runque.flushdb()
def inserturls():
runque = RedisQueueConnection('extracturls').conn
print runque.qsize()
raw_input('flushdb?')
runque.flushdb()
urls = flist('urlstogetip.txt')
for url in urls:
runque.put(url)
print runque.qsize()
def getsize(name):
runque = RedisQueueConnection(name).conn
print runque.qsize()
i = runque.get()
runque.put(i)
print i
def getsetsize(name):
runque = RedisConnection(name).conn
print runque.dbsize()
def show(name):
runque = RedisQueueConnection(name).conn
cnt = 0
while cnt < runque.qsize():
data = runque.get()
runque.put(data)
data = pickle.loads(data)
seed = data['seed']
data = data['content'].replace('\r', '\n').replace('\n\n','\n').strip()
if not data:
continue
if data.find('<') >= 0:
#html page
print seed
continue
robots = data.split('\n')
print seed
print
print "\n".join(robots)
print
cnt += 1
def insert():
runque = RedisQueueConnection('extracturls').conn
urls = flist('urlstogetrobots1.txt')[100000:300000]
print len(urls)
for url in urls:
runque.put(url)
def settest():
que = RedisConnection('test').conn
que.set('a',1)
print que.dbsize()
que.delete('a')
print que.get('a')
#rmdb('extracturls')
#test()
#run()
#inserturls()
#getsize('test')
#show('robots')
#insert()
#settest()
#getsetsize('test')