pull/17/head
yihua.huang 12 years ago
parent e5f4b3916f
commit c7005a0227

@ -40,6 +40,9 @@ public class Request implements Serializable {
private double priority;
public Request() {
}
/**
* request
*
@ -102,4 +105,12 @@ public class Request implements Serializable {
public int hashCode() {
return url.hashCode();
}
public void setExtras(Map<String, Object> extras) {
this.extras = extras;
}
public void setUrl(String url) {
this.url = url;
}
}

@ -40,8 +40,8 @@ public class RedisScheduler implements Scheduler {
jedis.zadd(SET_PREFIX + task.getUUID(), request.getPriority(), request.getUrl());
if (request.getExtras() != null) {
String key = ITEM_PREFIX + DigestUtils.shaHex(request.getUrl());
byte[] serialize = JSON.toJSONBytes(request);
jedis.set(key.getBytes(), serialize);
byte[] bytes = JSON.toJSONString(request).getBytes();
jedis.set(key.getBytes(), bytes);
}
}
pool.returnResource(jedis);
@ -57,8 +57,8 @@ public class RedisScheduler implements Scheduler {
String key = ITEM_PREFIX + DigestUtils.shaHex(url);
byte[] bytes = jedis.get(key.getBytes());
if (bytes != null) {
Object o = JSON.parse(bytes);
return (Request) o;
Request o = JSON.parseObject(new String(bytes),Request.class);
return o;
}
pool.returnResource(jedis);
return new Request(url);

@ -1,7 +1,6 @@
package us.codecraft.webmagic.scheduler;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Site;
@ -35,8 +34,11 @@ public class RedisSchedulerTest {
return null;
}
};
redisScheduler.push(new Request("http://www.ibm.com/developerworks/cn/java/j-javadev2-22/"), task);
Request request = new Request("http://www.ibm.com/developerworks/cn/java/j-javadev2-22/");
request.putExtra("1","2");
redisScheduler.push(request, task);
Request poll = redisScheduler.poll(task);
System.out.println(poll);
}
}

Loading…
Cancel
Save