redis in action javaコード追加コメント——Chapter 01
redis in actionを読みますhttps://github.com/josiahcarlson/redis-in-actionここでjavaコードをダウンロードして、いくつかの注釈を追加して、記憶を助けます
/**
* 'article:' , ID
* voted:ID set ,
* article:ID HASH ,
* score: ZSET (article:ID , )
* time:ZSET (article:ID , )
* group: set
* */
import redis.clients.jedis.Jedis;
import redis.clients.jedis.ZParams;
import java.util.*;
public class Chapter01 {
private static final int ONE_WEEK_IN_SECONDS = 7 * 86400;
private static final int VOTE_SCORE = 432;
private static final int ARTICLES_PER_PAGE = 25;
public static final void main(String[] args) {
new Chapter01().run();
}
public void run() {
Jedis conn = new Jedis("192.168.154.129", 6379);
conn.auth("password");
conn.select(15);
//
String articleId = postArticle(conn, "username", "A title", "http://www.google.com");
System.out.println("We posted a new article with id: " + articleId);
System.out.println("Its HASH looks like:");
Map articleData = conn.hgetAll("article:" + articleId);
for (Map.Entry entry : articleData.entrySet()) {
System.out.println(" " + entry.getKey() + ": " + entry.getValue());
}
System.out.println();
//
articleVote(conn, "other_user", "article:" + articleId);
String votes = conn.hget("article:" + articleId, "votes");
System.out.println("We voted for the article, it now has votes: " + votes);
assert Integer.parseInt(votes) > 1;
System.out.println("The currently highest-scoring articles are:");
//
List