PageRenderTime 31ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/redis/clients/jedis/BinaryShardedJedis.java

https://github.com/gnprice/jedis
Java | 403 lines | 324 code | 79 blank | 0 comment | 1 complexity | 19a784c9572ec010b30447ab71cf86e8 MD5 | raw file
  1. package redis.clients.jedis;
  2. import java.io.IOException;
  3. import java.util.Collection;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Set;
  7. import java.util.regex.Pattern;
  8. import redis.clients.jedis.BinaryClient.LIST_POSITION;
  9. import redis.clients.util.Hashing;
  10. import redis.clients.util.Sharded;
  11. public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
  12. implements BinaryJedisCommands {
  13. public BinaryShardedJedis(List<JedisShardInfo> shards) {
  14. super(shards);
  15. }
  16. public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo) {
  17. super(shards, algo);
  18. }
  19. public BinaryShardedJedis(List<JedisShardInfo> shards, Pattern keyTagPattern) {
  20. super(shards, keyTagPattern);
  21. }
  22. public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo,
  23. Pattern keyTagPattern) {
  24. super(shards, algo, keyTagPattern);
  25. }
  26. public void disconnect() throws IOException {
  27. for (Jedis jedis : getAllShards()) {
  28. jedis.disconnect();
  29. }
  30. }
  31. protected Jedis create(JedisShardInfo shard) {
  32. return new Jedis(shard);
  33. }
  34. public String set(byte[] key, byte[] value) {
  35. Jedis j = getShard(key);
  36. return j.set(key, value);
  37. }
  38. public byte[] get(byte[] key) {
  39. Jedis j = getShard(key);
  40. return j.get(key);
  41. }
  42. public Boolean exists(byte[] key) {
  43. Jedis j = getShard(key);
  44. return j.exists(key);
  45. }
  46. public String type(byte[] key) {
  47. Jedis j = getShard(key);
  48. return j.type(key);
  49. }
  50. public Long expire(byte[] key, int seconds) {
  51. Jedis j = getShard(key);
  52. return j.expire(key, seconds);
  53. }
  54. public Long expireAt(byte[] key, long unixTime) {
  55. Jedis j = getShard(key);
  56. return j.expireAt(key, unixTime);
  57. }
  58. public Long ttl(byte[] key) {
  59. Jedis j = getShard(key);
  60. return j.ttl(key);
  61. }
  62. public byte[] getSet(byte[] key, byte[] value) {
  63. Jedis j = getShard(key);
  64. return j.getSet(key, value);
  65. }
  66. public Long setnx(byte[] key, byte[] value) {
  67. Jedis j = getShard(key);
  68. return j.setnx(key, value);
  69. }
  70. public String setex(byte[] key, int seconds, byte[] value) {
  71. Jedis j = getShard(key);
  72. return j.setex(key, seconds, value);
  73. }
  74. public Long decrBy(byte[] key, long integer) {
  75. Jedis j = getShard(key);
  76. return j.decrBy(key, integer);
  77. }
  78. public Long decr(byte[] key) {
  79. Jedis j = getShard(key);
  80. return j.decr(key);
  81. }
  82. public Long incrBy(byte[] key, long integer) {
  83. Jedis j = getShard(key);
  84. return j.incrBy(key, integer);
  85. }
  86. public Long incr(byte[] key) {
  87. Jedis j = getShard(key);
  88. return j.incr(key);
  89. }
  90. public Long append(byte[] key, byte[] value) {
  91. Jedis j = getShard(key);
  92. return j.append(key, value);
  93. }
  94. public byte[] substr(byte[] key, int start, int end) {
  95. Jedis j = getShard(key);
  96. return j.substr(key, start, end);
  97. }
  98. public Long hset(byte[] key, byte[] field, byte[] value) {
  99. Jedis j = getShard(key);
  100. return j.hset(key, field, value);
  101. }
  102. public byte[] hget(byte[] key, byte[] field) {
  103. Jedis j = getShard(key);
  104. return j.hget(key, field);
  105. }
  106. public Long hsetnx(byte[] key, byte[] field, byte[] value) {
  107. Jedis j = getShard(key);
  108. return j.hsetnx(key, field, value);
  109. }
  110. public String hmset(byte[] key, Map<byte[], byte[]> hash) {
  111. Jedis j = getShard(key);
  112. return j.hmset(key, hash);
  113. }
  114. public List<byte[]> hmget(byte[] key, byte[]... fields) {
  115. Jedis j = getShard(key);
  116. return j.hmget(key, fields);
  117. }
  118. public Long hincrBy(byte[] key, byte[] field, long value) {
  119. Jedis j = getShard(key);
  120. return j.hincrBy(key, field, value);
  121. }
  122. public Boolean hexists(byte[] key, byte[] field) {
  123. Jedis j = getShard(key);
  124. return j.hexists(key, field);
  125. }
  126. public Long hdel(byte[] key, byte[] field) {
  127. Jedis j = getShard(key);
  128. return j.hdel(key, field);
  129. }
  130. public Long hlen(byte[] key) {
  131. Jedis j = getShard(key);
  132. return j.hlen(key);
  133. }
  134. public Set<byte[]> hkeys(byte[] key) {
  135. Jedis j = getShard(key);
  136. return j.hkeys(key);
  137. }
  138. public Collection<byte[]> hvals(byte[] key) {
  139. Jedis j = getShard(key);
  140. return j.hvals(key);
  141. }
  142. public Map<byte[], byte[]> hgetAll(byte[] key) {
  143. Jedis j = getShard(key);
  144. return j.hgetAll(key);
  145. }
  146. public Long rpush(byte[] key, byte[] string) {
  147. Jedis j = getShard(key);
  148. return j.rpush(key, string);
  149. }
  150. public Long lpush(byte[] key, byte[] string) {
  151. Jedis j = getShard(key);
  152. return j.lpush(key, string);
  153. }
  154. public Long llen(byte[] key) {
  155. Jedis j = getShard(key);
  156. return j.llen(key);
  157. }
  158. public List<byte[]> lrange(byte[] key, int start, int end) {
  159. Jedis j = getShard(key);
  160. return j.lrange(key, start, end);
  161. }
  162. public String ltrim(byte[] key, int start, int end) {
  163. Jedis j = getShard(key);
  164. return j.ltrim(key, start, end);
  165. }
  166. public byte[] lindex(byte[] key, int index) {
  167. Jedis j = getShard(key);
  168. return j.lindex(key, index);
  169. }
  170. public String lset(byte[] key, int index, byte[] value) {
  171. Jedis j = getShard(key);
  172. return j.lset(key, index, value);
  173. }
  174. public Long lrem(byte[] key, int count, byte[] value) {
  175. Jedis j = getShard(key);
  176. return j.lrem(key, count, value);
  177. }
  178. public byte[] lpop(byte[] key) {
  179. Jedis j = getShard(key);
  180. return j.lpop(key);
  181. }
  182. public byte[] rpop(byte[] key) {
  183. Jedis j = getShard(key);
  184. return j.rpop(key);
  185. }
  186. public Long sadd(byte[] key, byte[] member) {
  187. Jedis j = getShard(key);
  188. return j.sadd(key, member);
  189. }
  190. public Set<byte[]> smembers(byte[] key) {
  191. Jedis j = getShard(key);
  192. return j.smembers(key);
  193. }
  194. public Long srem(byte[] key, byte[] member) {
  195. Jedis j = getShard(key);
  196. return j.srem(key, member);
  197. }
  198. public byte[] spop(byte[] key) {
  199. Jedis j = getShard(key);
  200. return j.spop(key);
  201. }
  202. public Long scard(byte[] key) {
  203. Jedis j = getShard(key);
  204. return j.scard(key);
  205. }
  206. public Boolean sismember(byte[] key, byte[] member) {
  207. Jedis j = getShard(key);
  208. return j.sismember(key, member);
  209. }
  210. public byte[] srandmember(byte[] key) {
  211. Jedis j = getShard(key);
  212. return j.srandmember(key);
  213. }
  214. public Long zadd(byte[] key, double score, byte[] member) {
  215. Jedis j = getShard(key);
  216. return j.zadd(key, score, member);
  217. }
  218. public Set<byte[]> zrange(byte[] key, int start, int end) {
  219. Jedis j = getShard(key);
  220. return j.zrange(key, start, end);
  221. }
  222. public Long zrem(byte[] key, byte[] member) {
  223. Jedis j = getShard(key);
  224. return j.zrem(key, member);
  225. }
  226. public Double zincrby(byte[] key, double score, byte[] member) {
  227. Jedis j = getShard(key);
  228. return j.zincrby(key, score, member);
  229. }
  230. public Long zrank(byte[] key, byte[] member) {
  231. Jedis j = getShard(key);
  232. return j.zrank(key, member);
  233. }
  234. public Long zrevrank(byte[] key, byte[] member) {
  235. Jedis j = getShard(key);
  236. return j.zrevrank(key, member);
  237. }
  238. public Set<byte[]> zrevrange(byte[] key, int start, int end) {
  239. Jedis j = getShard(key);
  240. return j.zrevrange(key, start, end);
  241. }
  242. public Set<Tuple> zrangeWithScores(byte[] key, int start, int end) {
  243. Jedis j = getShard(key);
  244. return j.zrangeWithScores(key, start, end);
  245. }
  246. public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end) {
  247. Jedis j = getShard(key);
  248. return j.zrevrangeWithScores(key, start, end);
  249. }
  250. public Long zcard(byte[] key) {
  251. Jedis j = getShard(key);
  252. return j.zcard(key);
  253. }
  254. public Double zscore(byte[] key, byte[] member) {
  255. Jedis j = getShard(key);
  256. return j.zscore(key, member);
  257. }
  258. public List<byte[]> sort(byte[] key) {
  259. Jedis j = getShard(key);
  260. return j.sort(key);
  261. }
  262. public List<byte[]> sort(byte[] key, SortingParams sortingParameters) {
  263. Jedis j = getShard(key);
  264. return j.sort(key, sortingParameters);
  265. }
  266. public Long zcount(byte[] key, double min, double max) {
  267. Jedis j = getShard(key);
  268. return j.zcount(key, min, max);
  269. }
  270. public Set<byte[]> zrangeByScore(byte[] key, double min, double max) {
  271. Jedis j = getShard(key);
  272. return j.zrangeByScore(key, min, max);
  273. }
  274. public Set<byte[]> zrangeByScore(byte[] key, double min, double max,
  275. int offset, int count) {
  276. Jedis j = getShard(key);
  277. return j.zrangeByScore(key, min, max, offset, count);
  278. }
  279. public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) {
  280. Jedis j = getShard(key);
  281. return j.zrangeByScoreWithScores(key, min, max);
  282. }
  283. public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min,
  284. double max, int offset, int count) {
  285. Jedis j = getShard(key);
  286. return j.zrangeByScoreWithScores(key, min, max, offset, count);
  287. }
  288. public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) {
  289. Jedis j = getShard(key);
  290. return j.zrevrangeByScore(key, max, min);
  291. }
  292. public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min,
  293. int offset, int count) {
  294. Jedis j = getShard(key);
  295. return j.zrevrangeByScore(key, max, min, offset, count);
  296. }
  297. public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) {
  298. Jedis j = getShard(key);
  299. return j.zrevrangeByScoreWithScores(key, max, min);
  300. }
  301. public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max,
  302. double min, int offset, int count) {
  303. Jedis j = getShard(key);
  304. return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
  305. }
  306. public Long zremrangeByRank(byte[] key, int start, int end) {
  307. Jedis j = getShard(key);
  308. return j.zremrangeByRank(key, start, end);
  309. }
  310. public Long zremrangeByScore(byte[] key, double start, double end) {
  311. Jedis j = getShard(key);
  312. return j.zremrangeByScore(key, start, end);
  313. }
  314. public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot,
  315. byte[] value) {
  316. Jedis j = getShard(key);
  317. return j.linsert(key, where, pivot, value);
  318. }
  319. public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) {
  320. shardedJedisPipeline.setShardedJedis(this);
  321. shardedJedisPipeline.execute();
  322. return shardedJedisPipeline.getResults();
  323. }
  324. }