-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
升级相关版本依赖 #116
base: master
Are you sure you want to change the base?
升级相关版本依赖 #116
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,54 @@ | ||
package com.jarvis.cache.lock; | ||
|
||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.ShardedJedis; | ||
import redis.clients.jedis.ShardedJedisPool; | ||
import redis.clients.jedis.JedisSharding; | ||
import redis.clients.jedis.params.SetParams; | ||
|
||
/** | ||
* | ||
*/ | ||
public class ShardedJedisLock extends AbstractRedisLock { | ||
|
||
private ShardedJedisPool shardedJedisPool; | ||
private JedisSharding jedisSharding; | ||
|
||
public ShardedJedisLock(ShardedJedisPool shardedJedisPool) { | ||
this.shardedJedisPool = shardedJedisPool; | ||
public ShardedJedisLock(JedisSharding jedisSharding) { | ||
this.jedisSharding = jedisSharding; | ||
} | ||
|
||
private void returnResource(ShardedJedis shardedJedis) { | ||
shardedJedis.close(); | ||
private void returnResource(JedisSharding jedisSharding) { | ||
jedisSharding.close(); | ||
} | ||
|
||
@Override | ||
protected boolean setnx(String key, String val, int expire) { | ||
ShardedJedis shardedJedis = null; | ||
/*ShardedJedis shardedJedis = null; | ||
try { | ||
shardedJedis = shardedJedisPool.getResource(); | ||
Jedis jedis = shardedJedis.getShard(key); | ||
return OK.equalsIgnoreCase(jedis.set(key, val, SetParams.setParams().nx().ex(expire))); | ||
} finally { | ||
returnResource(shardedJedis); | ||
}*/ | ||
try { | ||
return OK.equalsIgnoreCase(jedisSharding.set(key, val, SetParams.setParams().nx().ex(expire))); | ||
} finally { | ||
returnResource(jedisSharding); | ||
} | ||
} | ||
|
||
@Override | ||
protected void del(String key) { | ||
ShardedJedis shardedJedis = null; | ||
/*ShardedJedis shardedJedis = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以删除这些代码 |
||
try { | ||
shardedJedis = shardedJedisPool.getResource(); | ||
Jedis jedis = shardedJedis.getShard(key); | ||
jedis.del(key); | ||
} finally { | ||
returnResource(shardedJedis); | ||
}*/ | ||
try { | ||
jedisSharding.del(key); | ||
} finally { | ||
returnResource(jedisSharding); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.jarvis.cache.lock; | ||
|
||
import redis.clients.jedis.JedisCluster; | ||
import redis.clients.jedis.params.SetParams; | ||
|
||
/** | ||
* | ||
*/ | ||
public class JedisClusterLock extends AbstractRedisLock { | ||
|
||
private JedisCluster jedisCluster; | ||
|
||
public JedisClusterLock(JedisCluster jedisCluster) { | ||
this.jedisCluster = jedisCluster; | ||
} | ||
|
||
@Override | ||
protected boolean setnx(String key, String val, int expire) { | ||
return OK.equalsIgnoreCase(jedisCluster.set(key, val, SetParams.setParams().nx().ex(expire))); | ||
} | ||
|
||
@Override | ||
protected void del(String key) { | ||
this.jedisCluster.del(key); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.jarvis.cache.lock; | ||
|
||
import redis.clients.jedis.JedisSharding; | ||
import redis.clients.jedis.params.SetParams; | ||
|
||
/** | ||
* | ||
*/ | ||
public class ShardedJedisLock extends AbstractRedisLock { | ||
|
||
private JedisSharding jedisSharding; | ||
|
||
public ShardedJedisLock(JedisSharding jedisSharding) { | ||
this.jedisSharding = jedisSharding; | ||
} | ||
|
||
private void returnResource(JedisSharding jedisSharding) { | ||
jedisSharding.close(); | ||
} | ||
|
||
@Override | ||
protected boolean setnx(String key, String val, int expire) { | ||
/*ShardedJedis shardedJedis = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 删除这些代码。 |
||
try { | ||
shardedJedis = shardedJedisPool.getResource(); | ||
Jedis jedis = shardedJedis.getShard(key); | ||
return OK.equalsIgnoreCase(jedis.set(key, val, SetParams.setParams().nx().ex(expire))); | ||
} finally { | ||
returnResource(shardedJedis); | ||
}*/ | ||
try { | ||
return OK.equalsIgnoreCase(jedisSharding.set(key, val, SetParams.setParams().nx().ex(expire))); | ||
} finally { | ||
returnResource(jedisSharding); | ||
} | ||
} | ||
|
||
@Override | ||
protected void del(String key) { | ||
/*ShardedJedis shardedJedis = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以删除这些代码 |
||
try { | ||
shardedJedis = shardedJedisPool.getResource(); | ||
Jedis jedis = shardedJedis.getShard(key); | ||
jedis.del(key); | ||
} finally { | ||
returnResource(shardedJedis); | ||
}*/ | ||
try { | ||
jedisSharding.del(key); | ||
} finally { | ||
returnResource(jedisSharding); | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以删除这些代码