|
7 | 7 | import com.google.gson.JsonObject; |
8 | 8 | import com.google.gson.JsonParser; |
9 | 9 | import fi.hsl.common.pulsar.PulsarApplicationContext; |
10 | | -import fi.hsl.common.transitdata.TransitdataProperties; |
11 | 10 | import org.jetbrains.annotations.NotNull; |
12 | | -import org.jetbrains.annotations.Nullable; |
13 | 11 | import org.slf4j.Logger; |
14 | 12 | import org.slf4j.LoggerFactory; |
15 | 13 | import redis.clients.jedis.*; |
|
19 | 17 | import java.nio.charset.StandardCharsets; |
20 | 18 | import java.time.Duration; |
21 | 19 | import java.time.OffsetDateTime; |
22 | | -import java.time.format.DateTimeFormatter; |
23 | 20 | import java.util.*; |
24 | 21 | import java.util.concurrent.ThreadLocalRandom; |
25 | 22 |
|
@@ -164,78 +161,6 @@ public List<String> getKeys(@NotNull final String prefix, @NotNull final String |
164 | 161 | return new ArrayList<>(keys); |
165 | 162 | } |
166 | 163 | } |
167 | | - |
168 | | - /** |
169 | | - * Fetches hash values for keys |
170 | | - * @param keys |
171 | | - * @return HashMap of keys and their hash values if they exist |
172 | | - */ |
173 | | - @NotNull |
174 | | - public Map<@NotNull String, Optional<Map<@NotNull String, @NotNull String>>> getValuesByKeys(@NotNull final List<@NotNull String> keys) { |
175 | | - synchronized (jedis) { |
176 | | - final Transaction transaction = jedis.multi(); |
177 | | - final Map<String, Response<Map<String, String>>> responses = new HashMap<>(); |
178 | | - keys.forEach(key -> responses.put(key, transaction.hgetAll(key))); |
179 | | - transaction.exec(); |
180 | | - |
181 | | - final Map<String, Optional<Map<String, String>>> values = new HashMap<>(responses.size()); |
182 | | - responses.forEach((k, v) -> { |
183 | | - final Map<String, String> value = v.get(); |
184 | | - if (value == null || value.isEmpty()) { |
185 | | - values.put(k, Optional.empty()); |
186 | | - } else { |
187 | | - values.put(k, Optional.of(value)); |
188 | | - } |
189 | | - }); |
190 | | - |
191 | | - return values; |
192 | | - } |
193 | | - } |
194 | | - |
195 | | - /** |
196 | | - * Fetches string values for keys |
197 | | - * @param keys |
198 | | - * @return HashMap of keys and their values if they exist |
199 | | - */ |
200 | | - @NotNull |
201 | | - public Map<@NotNull String, Optional<String>> getValueBykeys(@NotNull final List<@NotNull String> keys) { |
202 | | - synchronized (jedis) { |
203 | | - final Transaction transaction = jedis.multi(); |
204 | | - final Map<String, Response<String>> responses = new HashMap<>(); |
205 | | - keys.forEach(key -> responses.put(key, transaction.get(key))); |
206 | | - transaction.exec(); |
207 | | - |
208 | | - final Map<String, Optional<String>> values = new HashMap<>(responses.size()); |
209 | | - responses.forEach((k, v) -> { |
210 | | - final String value = v.get(); |
211 | | - if (value == null || value.isEmpty()) { |
212 | | - values.put(k, Optional.empty()); |
213 | | - } else { |
214 | | - values.put(k, Optional.of(value)); |
215 | | - } |
216 | | - }); |
217 | | - |
218 | | - return values; |
219 | | - } |
220 | | - } |
221 | | - |
222 | | - @NotNull |
223 | | - public String updateTimestamp() { |
224 | | - synchronized (jedis) { |
225 | | - final OffsetDateTime now = OffsetDateTime.now(); |
226 | | - final String ts = DateTimeFormatter.ISO_INSTANT.format(now); |
227 | | - log.info("Updating Redis timestamp to {}", ts); |
228 | | - return jedis.set(TransitdataProperties.KEY_LAST_CACHE_UPDATE_TIMESTAMP, ts); |
229 | | - } |
230 | | - } |
231 | | - |
232 | | - public boolean checkResponse(@Nullable final String response) { |
233 | | - return response != null && response.trim().equalsIgnoreCase("OK"); |
234 | | - } |
235 | | - |
236 | | - public boolean checkResponse(@Nullable final Long response) { |
237 | | - return response != null && response == 1; |
238 | | - } |
239 | 164 |
|
240 | 165 | // Azure Cache for Redis helper code |
241 | 166 | public static Jedis createJedisClient(String cacheHostname, int port, String username, AccessToken accessToken, boolean useSsl) { |
|
0 commit comments