From 1ab55e3f778d6cb7234851db42db9522f2181ea4 Mon Sep 17 00:00:00 2001 From: Senjin Hajrulahovic Date: Sat, 15 Apr 2023 09:30:22 +0200 Subject: [PATCH 1/5] issue/95 fix imports for moved classes --- .gitignore | 1 + java/build.gradle | 2 +- java/src/main/java/Chapter01.java | 2 +- java/src/main/java/Chapter02.java | 2 +- java/src/main/java/Chapter04.java | 2 +- java/src/main/java/Chapter05.java | 6 +++++- java/src/main/java/Chapter06.java | 4 ++-- java/src/main/java/Chapter07.java | 6 +++++- java/src/main/java/Chapter08.java | 2 +- java/src/main/java/Chapter09.java | 2 +- 10 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 25ae512..bf61e50 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.swp /java/build +/java/.gradle GeoLiteCity-*.csv .idea *.iml diff --git a/java/build.gradle b/java/build.gradle index 4994df9..6fc7b16 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -13,7 +13,7 @@ repositories { dependencies { - compile 'redis.clients:jedis:2.1.0' + compile 'redis.clients:jedis:4.3.2' compile 'org.javatuples:javatuples:1.2' compile 'com.google.code.gson:gson:2.2.2' diff --git a/java/src/main/java/Chapter01.java b/java/src/main/java/Chapter01.java index e66c0fa..5c8f82f 100644 --- a/java/src/main/java/Chapter01.java +++ b/java/src/main/java/Chapter01.java @@ -1,5 +1,5 @@ import redis.clients.jedis.Jedis; -import redis.clients.jedis.ZParams; +import redis.clients.jedis.params.ZParams; import java.util.*; diff --git a/java/src/main/java/Chapter02.java b/java/src/main/java/Chapter02.java index ec6db6b..dc316c6 100644 --- a/java/src/main/java/Chapter02.java +++ b/java/src/main/java/Chapter02.java @@ -1,6 +1,6 @@ import com.google.gson.Gson; import redis.clients.jedis.Jedis; -import redis.clients.jedis.Tuple; +import redis.clients.jedis.resps.Tuple; import java.net.MalformedURLException; import java.net.URL; diff --git a/java/src/main/java/Chapter04.java b/java/src/main/java/Chapter04.java index 2e6d38d..0f6d437 100644 --- a/java/src/main/java/Chapter04.java +++ b/java/src/main/java/Chapter04.java @@ -1,7 +1,7 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.Pipeline; import redis.clients.jedis.Transaction; -import redis.clients.jedis.Tuple; +import redis.clients.jedis.resps.Tuple; import java.lang.reflect.Method; import java.util.List; diff --git a/java/src/main/java/Chapter05.java b/java/src/main/java/Chapter05.java index 6574d53..5332c9c 100644 --- a/java/src/main/java/Chapter05.java +++ b/java/src/main/java/Chapter05.java @@ -2,7 +2,11 @@ import com.google.gson.reflect.TypeToken; import org.apache.commons.csv.CSVParser; import org.javatuples.Pair; -import redis.clients.jedis.*; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.Transaction; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.Pipeline; +import redis.clients.jedis.params.ZParams; import java.io.File; import java.io.FileReader; diff --git a/java/src/main/java/Chapter06.java b/java/src/main/java/Chapter06.java index c50dbd7..c2bb41f 100644 --- a/java/src/main/java/Chapter06.java +++ b/java/src/main/java/Chapter06.java @@ -2,8 +2,8 @@ import com.google.gson.reflect.TypeToken; import redis.clients.jedis.Jedis; import redis.clients.jedis.Transaction; -import redis.clients.jedis.Tuple; -import redis.clients.jedis.ZParams; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.params.ZParams; import java.io.*; import java.util.*; diff --git a/java/src/main/java/Chapter07.java b/java/src/main/java/Chapter07.java index 7d5162d..278abee 100644 --- a/java/src/main/java/Chapter07.java +++ b/java/src/main/java/Chapter07.java @@ -1,5 +1,9 @@ import org.javatuples.Pair; -import redis.clients.jedis.*; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.Transaction; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.SortingParams; import java.util.*; import java.util.regex.Matcher; diff --git a/java/src/main/java/Chapter08.java b/java/src/main/java/Chapter08.java index f3c64ce..2036d50 100644 --- a/java/src/main/java/Chapter08.java +++ b/java/src/main/java/Chapter08.java @@ -1,7 +1,7 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.Pipeline; import redis.clients.jedis.Transaction; -import redis.clients.jedis.Tuple; +import redis.clients.jedis.resps.Tuple; import java.lang.reflect.Method; import java.util.*; diff --git a/java/src/main/java/Chapter09.java b/java/src/main/java/Chapter09.java index 08e6740..8e5640f 100644 --- a/java/src/main/java/Chapter09.java +++ b/java/src/main/java/Chapter09.java @@ -1,7 +1,7 @@ import org.javatuples.Pair; import redis.clients.jedis.Jedis; import redis.clients.jedis.Pipeline; -import redis.clients.jedis.ZParams; +import redis.clients.jedis.params.ZParams; import java.io.IOException; import java.io.InputStream; From 22ba6824bc944ef72a79b6e47c0a8d60a8ce3905 Mon Sep 17 00:00:00 2001 From: Senjin Hajrulahovic Date: Sat, 15 Apr 2023 09:41:12 +0200 Subject: [PATCH 2/5] issue/95 Jedis.zrangeWithScores changed return type --- java/src/main/java/Chapter01.java | 2 +- java/src/main/java/Chapter02.java | 12 ++++++------ java/src/main/java/Chapter04.java | 2 +- java/src/main/java/Chapter05.java | 10 +++++----- java/src/main/java/Chapter06.java | 11 +++++------ java/src/main/java/Chapter07.java | 2 +- java/src/main/java/Chapter08.java | 8 ++++---- 7 files changed, 23 insertions(+), 24 deletions(-) diff --git a/java/src/main/java/Chapter01.java b/java/src/main/java/Chapter01.java index 5c8f82f..e2094a3 100644 --- a/java/src/main/java/Chapter01.java +++ b/java/src/main/java/Chapter01.java @@ -88,7 +88,7 @@ public List> getArticles(Jedis conn, int page, String order) int start = (page - 1) * ARTICLES_PER_PAGE; int end = start + ARTICLES_PER_PAGE - 1; - Set ids = conn.zrevrange(order, start, end); + List ids = conn.zrevrange(order, start, end); List> articles = new ArrayList>(); for (String id : ids){ Map articleData = conn.hgetAll(id); diff --git a/java/src/main/java/Chapter02.java b/java/src/main/java/Chapter02.java index dc316c6..75e20e5 100644 --- a/java/src/main/java/Chapter02.java +++ b/java/src/main/java/Chapter02.java @@ -103,7 +103,7 @@ public void testCacheRows(Jedis conn) System.out.println("First, let's schedule caching of itemX every 5 seconds"); scheduleRowCache(conn, "itemX", 5); System.out.println("Our schedule looks like:"); - Set s = conn.zrangeWithScores("schedule:", 0, -1); + List s = conn.zrangeWithScores("schedule:", 0, -1); for (Tuple tuple : s){ System.out.println(" " + tuple.getElement() + ", " + tuple.getScore()); } @@ -285,8 +285,8 @@ public void run() { } long endIndex = Math.min(size - limit, 100); - Set tokenSet = conn.zrange("recent:", 0, endIndex - 1); - String[] tokens = tokenSet.toArray(new String[tokenSet.size()]); + List tokenList = conn.zrange("recent:", 0, endIndex - 1); + String[] tokens = tokenList.toArray(new String[tokenList.size()]); ArrayList sessionKeys = new ArrayList(); for (String token : tokens) { @@ -330,8 +330,8 @@ public void run() { } long endIndex = Math.min(size - limit, 100); - Set sessionSet = conn.zrange("recent:", 0, endIndex - 1); - String[] sessions = sessionSet.toArray(new String[sessionSet.size()]); + List sessionList = conn.zrange("recent:", 0, endIndex - 1); + String[] sessions = sessionList.toArray(new String[sessionList.size()]); ArrayList sessionKeys = new ArrayList(); for (String sess : sessions) { @@ -364,7 +364,7 @@ public void quit() { public void run() { Gson gson = new Gson(); while (!quit){ - Set range = conn.zrangeWithScores("schedule:", 0, 0); + List range = conn.zrangeWithScores("schedule:", 0, 0); Tuple next = range.size() > 0 ? range.iterator().next() : null; long now = System.currentTimeMillis() / 1000; if (next == null || next.getScore() > now){ diff --git a/java/src/main/java/Chapter04.java b/java/src/main/java/Chapter04.java index 0f6d437..6042d95 100644 --- a/java/src/main/java/Chapter04.java +++ b/java/src/main/java/Chapter04.java @@ -44,7 +44,7 @@ public void testListItem(Jedis conn, boolean nested) { boolean l = listItem(conn, item, seller, 10); System.out.println("Listing the item succeeded? " + l); assert l; - Set r = conn.zrangeWithScores("market:", 0, -1); + List r = conn.zrangeWithScores("market:", 0, -1); System.out.println("The market contains:"); for (Tuple tuple : r){ System.out.println(" " + tuple.getElement() + ", " + tuple.getScore()); diff --git a/java/src/main/java/Chapter05.java b/java/src/main/java/Chapter05.java index 5332c9c..1f032e7 100644 --- a/java/src/main/java/Chapter05.java +++ b/java/src/main/java/Chapter05.java @@ -78,7 +78,7 @@ public void testLogCommon(Jedis conn) { logCommon(conn, "test", "message-" + count); } } - Set common = conn.zrevrangeWithScores("common:test:info", 0, -1); + List common = conn.zrevrangeWithScores("common:test:info", 0, -1); System.out.println("The current number of common messages is: " + common.size()); System.out.println("Those common messages are:"); for (Tuple tuple : common){ @@ -153,7 +153,7 @@ public void testAccessTime(Jedis conn) timer.stop("req-" + i); } System.out.println("The slowest access times are:"); - Set atimes = conn.zrevrangeWithScores("slowest:AccessTime", 0, -1); + List atimes = conn.zrevrangeWithScores("slowest:AccessTime", 0, -1); for (Tuple tuple : atimes){ System.out.println(" " + tuple.getElement() + ", " + tuple.getScore()); } @@ -359,7 +359,7 @@ public List updateStats(Jedis conn, String context, String type, double public Map getStats(Jedis conn, String context, String type){ String key = "stats:" + context + ':' + type; Map stats = new HashMap(); - Set data = conn.zrangeWithScores(key, 0, -1); + List data = conn.zrangeWithScores(key, 0, -1); for (Tuple tuple : data){ stats.put(tuple.getElement(), tuple.getScore()); } @@ -523,7 +523,7 @@ public String randomOctet(int max) { public String[] findCityByIp(Jedis conn, String ipAddress) { int score = ipToScore(ipAddress); - Set results = conn.zrevrangeByScore("ip2cityid:", score, 0, 0, 1); + List results = conn.zrevrangeByScore("ip2cityid:", score, 0, 0, 1); if (results.size() == 0) { return null; } @@ -558,7 +558,7 @@ public void run(){ long start = System.currentTimeMillis() + timeOffset; int index = 0; while (index < conn.zcard("known:")){ - Set hashSet = conn.zrange("known:", index, index); + List hashSet = conn.zrange("known:", index, index); index++; if (hashSet.size() == 0) { break; diff --git a/java/src/main/java/Chapter06.java b/java/src/main/java/Chapter06.java index c2bb41f..c56be02 100644 --- a/java/src/main/java/Chapter06.java +++ b/java/src/main/java/Chapter06.java @@ -586,8 +586,7 @@ public String sendMessage(Jedis conn, String chatId, String sender, String messa @SuppressWarnings("unchecked") public List fetchPendingMessages(Jedis conn, String recipient) { - Set seenSet = conn.zrangeWithScores("seen:" + recipient, 0, -1); - List seenList = new ArrayList(seenSet); + List seenList = conn.zrangeWithScores("seen:" + recipient, 0, -1); Transaction trans = conn.multi(); for (Tuple tuple : seenList){ @@ -628,10 +627,10 @@ public List fetchPendingMessages(Jedis conn, String recipient) { conn.zadd("chat:" + chatId, seenId, recipient); seenUpdates.add(new Object[]{"seen:" + recipient, seenId, chatId}); - Set minIdSet = conn.zrangeWithScores("chat:" + chatId, 0, 0); - if (minIdSet.size() > 0){ + List minIdList = conn.zrangeWithScores("chat:" + chatId, 0, 0); + if (minIdList.size() > 0){ msgRemoves.add(new Object[]{ - "msgs:" + chatId, minIdSet.iterator().next().getScore()}); + "msgs:" + chatId, minIdList.iterator().next().getScore()}); } chatMessages.add(new ChatMessages(chatId, messages)); } @@ -789,7 +788,7 @@ public void quit() { public void run() { while (!quit){ - Set items = conn.zrangeWithScores("delayed:", 0, 0); + List items = conn.zrangeWithScores("delayed:", 0, 0); Tuple item = items.size() > 0 ? items.iterator().next() : null; if (item == null || item.getScore() > System.currentTimeMillis()) { try{ diff --git a/java/src/main/java/Chapter07.java b/java/src/main/java/Chapter07.java index 278abee..7bbf6bf 100644 --- a/java/src/main/java/Chapter07.java +++ b/java/src/main/java/Chapter07.java @@ -885,7 +885,7 @@ public void indexJob(Jedis conn, String jobId, String... skills) { trans.exec(); } - public Set findJobs(Jedis conn, String... candidateSkills) { + public List findJobs(Jedis conn, String... candidateSkills) { String[] keys = new String[candidateSkills.length]; int[] weights = new int[candidateSkills.length]; for (int i = 0; i < candidateSkills.length; i++) { diff --git a/java/src/main/java/Chapter08.java b/java/src/main/java/Chapter08.java index 2036d50..58969f3 100644 --- a/java/src/main/java/Chapter08.java +++ b/java/src/main/java/Chapter08.java @@ -349,7 +349,7 @@ public long postStatus( public void syndicateStatus( Jedis conn, long uid, long postId, long postTime, double start) { - Set followers = conn.zrangeByScoreWithScores( + List followers = conn.zrangeByScoreWithScores( "followers:" + uid, String.valueOf(start), "inf", 0, POSTS_PER_PASS); @@ -409,7 +409,7 @@ public List> getStatusMessages(Jedis conn, long uid) { public List> getStatusMessages( Jedis conn, long uid, int page, int count) { - Set statusIds = conn.zrevrange( + List statusIds = conn.zrevrange( "home:" + uid, (page - 1) * count, page * count - 1); Transaction trans = conn.multi(); @@ -439,7 +439,7 @@ public void refillTimeline( return; } - Set users = conn.zrangeByScoreWithScores( + List users = conn.zrangeByScoreWithScores( incoming, String.valueOf(start), "inf", 0, REFILL_USERS_STEP); Pipeline pipeline = conn.pipelined(); @@ -491,7 +491,7 @@ public void cleanTimelines( key = "list:out:" + uid; base = "list:statuses:"; } - Set followers = conn.zrangeByScoreWithScores( + List followers = conn.zrangeByScoreWithScores( key, String.valueOf(start), "inf", 0, POSTS_PER_PASS); Transaction trans = conn.multi(); From d6fa852aaccaa40c75a766dbe49349a137e82289 Mon Sep 17 00:00:00 2001 From: Senjin Hajrulahovic Date: Sat, 15 Apr 2023 09:48:25 +0200 Subject: [PATCH 3/5] issue/95 Jedis APIs which changed parameter/return types * ZParams.weights * Jedis.zadd --- java/src/main/java/Chapter07.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/java/src/main/java/Chapter07.java b/java/src/main/java/Chapter07.java index 7bbf6bf..851e180 100644 --- a/java/src/main/java/Chapter07.java +++ b/java/src/main/java/Chapter07.java @@ -596,9 +596,9 @@ public long stringToScoreGeneric(String string, Map mapping) { } public long zaddString(Jedis conn, String name, Map values) { - Map pieces = new HashMap(values.size()); + Map pieces = new HashMap(values.size()); for (Map.Entry entry : values.entrySet()) { - pieces.put((double)stringToScore(entry.getValue()), entry.getKey()); + pieces.put(entry.getKey(), (double)stringToScore(entry.getValue())); } return conn.zadd(name, pieces); @@ -697,7 +697,7 @@ public Pair,String> finishScoring( if (bonusEcpm.size() > 0){ String[] keys = new String[bonusEcpm.size()]; - int[] weights = new int[bonusEcpm.size()]; + double[] weights = new double[bonusEcpm.size()]; int index = 0; for (Map.Entry bonus : bonusEcpm.entrySet()){ keys[index] = bonus.getKey(); @@ -887,7 +887,7 @@ public void indexJob(Jedis conn, String jobId, String... skills) { public List findJobs(Jedis conn, String... candidateSkills) { String[] keys = new String[candidateSkills.length]; - int[] weights = new int[candidateSkills.length]; + double[] weights = new double[candidateSkills.length]; for (int i = 0; i < candidateSkills.length; i++) { keys[i] = "skill:" + candidateSkills[i]; weights[i] = 1; From dc3144206670d8a17a9a8ef000ab22727cee8f81 Mon Sep 17 00:00:00 2001 From: Senjin Hajrulahovic Date: Sat, 15 Apr 2023 10:03:10 +0200 Subject: [PATCH 4/5] issue/95 Pipeline changed API --- java/src/main/java/Chapter04.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/java/src/main/java/Chapter04.java b/java/src/main/java/Chapter04.java index 6042d95..f9ba81a 100644 --- a/java/src/main/java/Chapter04.java +++ b/java/src/main/java/Chapter04.java @@ -201,7 +201,6 @@ public void updateToken(Jedis conn, String token, String user, String item) { public void updateTokenPipeline(Jedis conn, String token, String user, String item) { long timestamp = System.currentTimeMillis() / 1000; Pipeline pipe = conn.pipelined(); - pipe.multi(); pipe.hset("login:", token, user); pipe.zadd("recent:", timestamp, token); if (item != null){ @@ -209,6 +208,6 @@ public void updateTokenPipeline(Jedis conn, String token, String user, String it pipe.zremrangeByRank("viewed:" + token, 0, -26); pipe.zincrby("viewed:", -1, item); } - pipe.exec(); + pipe.sync(); } } From b1c48020aa083fef31698f0781478e8fe71b6ec5 Mon Sep 17 00:00:00 2001 From: Senjin Hajrulahovic Date: Sat, 15 Apr 2023 11:15:27 +0200 Subject: [PATCH 5/5] issue/95 fix reflection code --- java/src/main/java/Chapter01.java | 2 +- java/src/main/java/Chapter02.java | 8 ++++---- java/src/main/java/Chapter04.java | 2 +- java/src/main/java/Chapter05.java | 8 ++++---- java/src/main/java/Chapter06.java | 6 +++--- java/src/main/java/Chapter07.java | 12 ++++++------ java/src/main/java/Chapter08.java | 6 +++--- java/src/main/java/Chapter09.java | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/java/src/main/java/Chapter01.java b/java/src/main/java/Chapter01.java index e2094a3..22ebaa0 100644 --- a/java/src/main/java/Chapter01.java +++ b/java/src/main/java/Chapter01.java @@ -13,7 +13,7 @@ public static final void main(String[] args) { } public void run() { - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); conn.select(15); String articleId = postArticle( diff --git a/java/src/main/java/Chapter02.java b/java/src/main/java/Chapter02.java index 75e20e5..cb443cc 100644 --- a/java/src/main/java/Chapter02.java +++ b/java/src/main/java/Chapter02.java @@ -16,7 +16,7 @@ public static final void main(String[] args) public void run() throws InterruptedException { - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); conn.select(15); testLoginCookies(conn); @@ -263,7 +263,7 @@ public class CleanSessionsThread private boolean quit; public CleanSessionsThread(int limit) { - this.conn = new Jedis("localhost"); + this.conn = new Jedis("redis://localhost:6379"); this.conn.select(15); this.limit = limit; } @@ -308,7 +308,7 @@ public class CleanFullSessionsThread private boolean quit; public CleanFullSessionsThread(int limit) { - this.conn = new Jedis("localhost"); + this.conn = new Jedis("redis://localhost:6379"); this.conn.select(15); this.limit = limit; } @@ -353,7 +353,7 @@ public class CacheRowsThread private boolean quit; public CacheRowsThread() { - this.conn = new Jedis("localhost"); + this.conn = new Jedis("redis://localhost:6379"); this.conn.select(15); } diff --git a/java/src/main/java/Chapter04.java b/java/src/main/java/Chapter04.java index f9ba81a..9f48a4b 100644 --- a/java/src/main/java/Chapter04.java +++ b/java/src/main/java/Chapter04.java @@ -14,7 +14,7 @@ public static final void main(String[] args) { } public void run() { - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); conn.select(15); testListItem(conn, false); diff --git a/java/src/main/java/Chapter05.java b/java/src/main/java/Chapter05.java index 1f032e7..8736311 100644 --- a/java/src/main/java/Chapter05.java +++ b/java/src/main/java/Chapter05.java @@ -40,7 +40,7 @@ public static final void main(String[] args) public void run() throws InterruptedException { - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); conn.select(15); testLogRecent(conn); @@ -422,7 +422,7 @@ public Map getConfig(Jedis conn, String type, String component) { public Jedis redisConnection(String component){ Jedis configConn = REDIS_CONNECTIONS.get("config"); if (configConn == null){ - configConn = new Jedis("localhost"); + configConn = new Jedis("redis://localhost:6379"); configConn.select(15); REDIS_CONNECTIONS.put("config", configConn); } @@ -432,7 +432,7 @@ public Jedis redisConnection(String component){ Map config = getConfig(configConn, "redis", component); if (!config.equals(oldConfig)){ - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); if (config.containsKey("db")){ conn.select(((Double)config.get("db")).intValue()); } @@ -542,7 +542,7 @@ public class CleanCountersThread private long timeOffset; // used to mimic a time in the future. public CleanCountersThread(int sampleCount, long timeOffset){ - this.conn = new Jedis("localhost"); + this.conn = new Jedis("redis://localhost:6379"); this.conn.select(15); this.sampleCount = sampleCount; this.timeOffset = timeOffset; diff --git a/java/src/main/java/Chapter06.java b/java/src/main/java/Chapter06.java index c56be02..8adbb91 100644 --- a/java/src/main/java/Chapter06.java +++ b/java/src/main/java/Chapter06.java @@ -20,7 +20,7 @@ public static final void main(String[] args) public void run() throws InterruptedException, IOException { - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); conn.select(15); testAddUpdateContact(conn); @@ -778,7 +778,7 @@ public class PollQueueThread private Gson gson = new Gson(); public PollQueueThread(){ - this.conn = new Jedis("localhost"); + this.conn = new Jedis("redis://localhost:6379"); this.conn.select(15); } @@ -828,7 +828,7 @@ public class CopyLogsThread private long limit; public CopyLogsThread(File path, String channel, int count, long limit) { - this.conn = new Jedis("localhost"); + this.conn = new Jedis("redis://localhost:6379"); this.conn.select(15); this.path = path; this.channel = channel; diff --git a/java/src/main/java/Chapter07.java b/java/src/main/java/Chapter07.java index 851e180..277b331 100644 --- a/java/src/main/java/Chapter07.java +++ b/java/src/main/java/Chapter07.java @@ -42,7 +42,7 @@ public static final void main(String[] args) { } public void run(){ - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); conn.select(15); conn.flushDB(); @@ -360,7 +360,7 @@ private String setCommon( String id = UUID.randomUUID().toString(); try{ - trans.getClass() + trans.getClass().getSuperclass() .getDeclaredMethod(method, String.class, String[].class) .invoke(trans, "idx:" + id, keys); }catch(Exception e){ @@ -392,7 +392,7 @@ private String zsetCommon( String id = UUID.randomUUID().toString(); try{ - trans.getClass() + trans.getClass().getSuperclass() .getDeclaredMethod(method, String.class, ZParams.class, String[].class) .invoke(trans, "idx:" + id, params, keys); }catch(Exception e){ @@ -547,7 +547,7 @@ public SearchResult searchAndZsort( id, ((Long)results.get(results.size() - 2)).longValue(), // Note: it's a LinkedHashSet, so it's ordered - new ArrayList((Set)results.get(results.size() - 1))); + (List)results.get(results.size() - 1)); } public long stringToScore(String string) { @@ -596,7 +596,7 @@ public long stringToScoreGeneric(String string, Map mapping) { } public long zaddString(Jedis conn, String name, Map values) { - Map pieces = new HashMap(values.size()); + Map pieces = new HashMap(values.size()); for (Map.Entry entry : values.entrySet()) { pieces.put(entry.getKey(), (double)stringToScore(entry.getValue())); } @@ -663,7 +663,7 @@ public Pair targetAds( List response = trans.exec(); long targetId = (Long)response.get(response.size() - 2); - Set targetedAds = (Set)response.get(response.size() - 1); + List targetedAds = (List)response.get(response.size() - 1); if (targetedAds.size() == 0){ return new Pair(null, null); diff --git a/java/src/main/java/Chapter08.java b/java/src/main/java/Chapter08.java index 58969f3..1743255 100644 --- a/java/src/main/java/Chapter08.java +++ b/java/src/main/java/Chapter08.java @@ -20,7 +20,7 @@ public static final void main(String[] args) public void run() throws InterruptedException { - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); conn.select(15); conn.flushDB(); @@ -239,7 +239,7 @@ public boolean followUser(Jedis conn, long uid, long otherUid) { List response = trans.exec(); long following = (Long)response.get(response.size() - 3); long followers = (Long)response.get(response.size() - 2); - Set statuses = (Set)response.get(response.size() - 1); + List statuses = (ArrayList)response.get(response.size() - 1); trans = conn.multi(); trans.hset("user:" + uid, "following", String.valueOf(following)); @@ -538,7 +538,7 @@ public MethodThread(Object instance, Method method, Object... args) { } public void run() { - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); conn.select(15); Object[] args = new Object[this.args.length + 1]; diff --git a/java/src/main/java/Chapter09.java b/java/src/main/java/Chapter09.java index 8e5640f..53de58c 100644 --- a/java/src/main/java/Chapter09.java +++ b/java/src/main/java/Chapter09.java @@ -46,7 +46,7 @@ public static final void main(String[] args) { } public void run() { - Jedis conn = new Jedis("localhost"); + Jedis conn = new Jedis("redis://localhost:6379"); conn.select(15); conn.flushDB();