redis.clients.jedis.params.SetParams Java Examples
The following examples show how to use
redis.clients.jedis.params.SetParams.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JedisClusterUtil.java From NetworkDisk_Storage with GNU General Public License v2.0 | 6 votes |
/** * 缓存value * * @param nxxx NX|XX, NX -- Only set the key if it does not already exist. XX * -- Only set the key */ public boolean setValue(String key, String value, String nxxx, int seconds) { try { SetParams setParams = new SetParams(); setParams.ex(seconds); String str = jedisCluster.set(key, value, setParams); if ("OK".equals(str)) { return true; } } catch (Exception e) { log.error("redis操作失败, key:{},value:{}", key, value, new CacheException(e)); } finally { //jedisCluster.close(); } return false; }
Example #2
Source File: RedisCache.java From jetcache with Apache License 2.0 | 6 votes |
@Override protected CacheResult do_PUT_IF_ABSENT(K key, V value, long expireAfterWrite, TimeUnit timeUnit) { try (Jedis jedis = config.getJedisPool().getResource()) { CacheValueHolder<V> holder = new CacheValueHolder(value, timeUnit.toMillis(expireAfterWrite)); byte[] newKey = buildKey(key); SetParams params = new SetParams(); params.nx() .px(timeUnit.toMillis(expireAfterWrite)); String rt = jedis.set(newKey, valueEncoder.apply(holder), params); if ("OK".equals(rt)) { return CacheResult.SUCCESS_WITHOUT_MSG; } else if (rt == null) { return CacheResult.EXISTS_WITHOUT_MSG; } else { return new CacheResult(CacheResultCode.FAIL, rt); } } catch (Exception ex) { logError("PUT_IF_ABSENT", key, ex); return new CacheResult(ex); } }
Example #3
Source File: DynoJedisClient.java From dyno with Apache License 2.0 | 6 votes |
public OperationResult<String> d_set(final String key, final String value, final String nxxx, final String expx, final long time) { SetParams setParams = SetParams.setParams(); if (nxxx.equalsIgnoreCase("NX")) { setParams.nx(); } else if (nxxx.equalsIgnoreCase("XX")) { setParams.xx(); } if (expx.equalsIgnoreCase("EX")) { setParams.ex((int) time); } else if (expx.equalsIgnoreCase("PX")) { setParams.px(time); } return d_set(key, value, setParams); }
Example #4
Source File: ExtendHost.java From dyno with Apache License 2.0 | 5 votes |
public ExtendHost(Host host, ConnectionPool pool, LockResource lockResource, CountDownLatch latch, String randomKey) { super(host, pool); this.lockResource = lockResource; this.value = lockResource.getResource(); this.params = SetParams.setParams().px(lockResource.getTtlMs()); this.randomKey = randomKey; this.latch = latch; }
Example #5
Source File: PubsubMessageHandler.java From echo with Apache License 2.0 | 5 votes |
private boolean acquireMessageLock(String messageKey, String identifier, int ackDeadlineSeconds) { String response = redisClientDelegate.withCommandsClient( c -> { return c.set( messageKey, identifier, SetParams.setParams().nx().ex(ackDeadlineSeconds)); }); return SUCCESS.equals(response); }
Example #6
Source File: AbstractRedisStorage.java From quartz-redis-jobstore with Apache License 2.0 | 5 votes |
/** * Attempt to acquire a lock * @return true if lock was successfully acquired; false otherwise */ public boolean lock(T jedis){ UUID lockId = UUID.randomUUID(); final String setResponse = jedis.set(redisSchema.lockKey(), lockId.toString(), SetParams.setParams().nx().px(lockTimeout)); boolean lockAcquired = !isNullOrEmpty(setResponse) && setResponse.equals("OK"); if(lockAcquired){ // save the random value used to lock so that we can successfully unlock later lockValue = lockId; } return lockAcquired; }
Example #7
Source File: ShardedJedisLock.java From AutoLoadCache with Apache License 2.0 | 5 votes |
@Override protected boolean setnx(String key, String val, int expire) { 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); } }
Example #8
Source File: RedisService.java From pybbs with GNU Affero General Public License v3.0 | 5 votes |
/** * 带有过期时间的保存数据到redis,到期自动删除 * * @param key * @param value * @param expireTime 单位 秒 */ public void setString(String key, String value, int expireTime) { JedisPool instance = this.instance(); if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value) || instance == null) return; Jedis jedis = instance.getResource(); SetParams params = new SetParams(); params.px(expireTime * 1000); jedis.set(key, value, params); jedis.close(); }
Example #9
Source File: RedisService.java From pybbs with GNU Affero General Public License v3.0 | 5 votes |
/** * 带有过期时间的保存数据到redis,到期自动删除 * * @param key * @param value * @param expireTime 单位 秒 */ public void setString(String key, String value, int expireTime) { JedisPool instance = this.instance(); if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value) || instance == null) return; Jedis jedis = instance.getResource(); SetParams params = new SetParams(); params.px(expireTime * 1000); jedis.set(key, value, params); jedis.close(); }
Example #10
Source File: DynoJedisClient.java From dyno with Apache License 2.0 | 5 votes |
public OperationResult<String> d_set(final byte[] key, final byte[] value, final SetParams setParams) { return connPool.executeWithFailover(new BaseKeyOperation<String>(key, OpName.SET) { @Override public String execute(Jedis client, ConnectionContext state) throws DynoException { return client.set(key, value, setParams); } }); }
Example #11
Source File: LockHost.java From dyno with Apache License 2.0 | 5 votes |
public LockHost(Host host, ConnectionPool pool, LockResource lockResource, CountDownLatch latch, String randomKey) { super(host, pool); this.lockResource = lockResource; this.value = lockResource.getResource(); this.params = SetParams.setParams().nx().px(lockResource.getTtlMs()); this.randomKey = randomKey; this.latch = latch; }
Example #12
Source File: MarsRedisLock.java From Mars-Java with MIT License | 5 votes |
/** * 加锁,使用你自己创建的jedis对象 * * @param key 键 * @param value 值 * @param shardedJedis 自己创建的jedis对象 * @return */ public boolean lock(String key, String value, ShardedJedis shardedJedis) { try { if (shardedJedis == null) { return false; } int count = 0; SetParams params = SetParams.setParams().nx().px(5000); String result = shardedJedis.set(key, value, params); while (result == null || !result.toUpperCase().equals("OK")) { /* 如果设置失败,代表这个key已经存在了,也就说明锁被占用了,则进入等待 */ Thread.sleep(500); if (count >= 19) { /* 10秒后还没有获取锁,则停止等待 */ return false; } result = shardedJedis.set(key, value, params); count++; } return true; } catch (Exception e) { logger.error("获取redis锁发生异常", e); return false; } finally { marsRedisTemplate.recycleJedis(shardedJedis); } }
Example #13
Source File: TracingJedisCluster.java From java-redis-client with Apache License 2.0 | 5 votes |
@Override public String set(byte[] key, byte[] value, SetParams params) { Span span = helper.buildSpan("set", key); span.setTag("value", Arrays.toString(value)); span.setTag("params", TracingHelper.toString(params.getByteParams())); return helper.decorate(span, () -> super.set(key, value, params)); }
Example #14
Source File: TracingJedisCluster.java From java-redis-client with Apache License 2.0 | 5 votes |
@Override public String set(String key, String value, SetParams params) { Span span = helper.buildSpan("set", key); span.setTag("value", value); span.setTag("params", TracingHelper.toString(params.getByteParams())); return helper.decorate(span, () -> super.set(key, value, params)); }
Example #15
Source File: TracingJedisWrapper.java From java-redis-client with Apache License 2.0 | 5 votes |
@Override public String set(byte[] key, byte[] value, SetParams params) { Span span = helper.buildSpan("set", key); span.setTag("value", Arrays.toString(value)); span.setTag("params", TracingHelper.toString(params.getByteParams())); return helper.decorate(span, () -> wrapped.set(key, value, params)); }
Example #16
Source File: TracingJedisWrapper.java From java-redis-client with Apache License 2.0 | 5 votes |
@Override public String set(String key, String value, SetParams params) { Span span = helper.buildSpan("set", key); span.setTag("value", value); span.setTag("params", nullable(TracingHelper.toString(params.getByteParams()))); return helper.decorate(span, () -> wrapped.set(key, value, params)); }
Example #17
Source File: InstrumentedJedis.java From kork with Apache License 2.0 | 4 votes |
@Override public String set(final byte[] key, final byte[] value, final SetParams params) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value, params)); }
Example #18
Source File: InstrumentedPipeline.java From kork with Apache License 2.0 | 4 votes |
@Override public Response<String> set(String key, String value, SetParams params) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value, params)); }
Example #19
Source File: InstrumentedPipeline.java From kork with Apache License 2.0 | 4 votes |
@Override public Response<String> set(byte[] key, byte[] value, SetParams params) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value, params)); }
Example #20
Source File: InstrumentedJedis.java From kork with Apache License 2.0 | 4 votes |
@Override public String set(String key, String value, SetParams params) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value, params)); }
Example #21
Source File: DynoJedisClient.java From dyno with Apache License 2.0 | 4 votes |
@Override public String set(final byte[] key, final byte[] value, final SetParams setParams) { return d_set(key, value, setParams).getResult(); }
Example #22
Source File: DynoJedisClient.java From dyno with Apache License 2.0 | 4 votes |
public String set(final String key, final String value, final SetParams setParams) { return d_set(key, value, setParams).getResult(); }
Example #23
Source File: DynoJedisPipeline.java From dyno with Apache License 2.0 | 4 votes |
@Override public Response<String> set(byte[] key, byte[] value, SetParams params) { throw new UnsupportedOperationException("not yet implemented"); }
Example #24
Source File: DynoJedisPipeline.java From dyno with Apache License 2.0 | 4 votes |
@Override public Response<String> set(String key, String value, SetParams params) { return null; }
Example #25
Source File: JedisClusterCommandsWrapper.java From quartz-redis-jobstore with Apache License 2.0 | 4 votes |
@Override public String set(String s, String s1, SetParams setParams) { return cluster.set(s, s1, setParams); }
Example #26
Source File: JedisClusterLock.java From AutoLoadCache with Apache License 2.0 | 4 votes |
@Override protected boolean setnx(String key, String val, int expire) { return OK.equalsIgnoreCase(jedisCluster.set(key, val, SetParams.setParams().nx().ex(expire))); }
Example #27
Source File: JedisLockProvider.java From ShedLock with Apache License 2.0 | 4 votes |
@Override public String set(String key, String value, SetParams setParams) { return jedisCluster.set(key, value, setParams); }
Example #28
Source File: JedisLockProvider.java From ShedLock with Apache License 2.0 | 4 votes |
@Override public String set(String key, String value, SetParams setParams) { try (Jedis jedis = jedisPool.getResource()) { return jedis.set(key, value, setParams); } }
Example #29
Source File: JedisSentinelTest.java From conductor with Apache License 2.0 | 4 votes |
@Test public void testSet() { jedisSentinel.set("key", "value"); jedisSentinel.set("key", "value", SetParams.setParams()); }
Example #30
Source File: JedisClusterlTest.java From conductor with Apache License 2.0 | 4 votes |
@Test public void testSet() { jedisCluster.set("key", "value"); jedisCluster.set("key", "value", SetParams.setParams()); }