当前位置: 首页>>代码示例>>Java>>正文


Java DefaultRedisScript类代码示例

本文整理汇总了Java中org.springframework.data.redis.core.script.DefaultRedisScript的典型用法代码示例。如果您正苦于以下问题:Java DefaultRedisScript类的具体用法?Java DefaultRedisScript怎么用?Java DefaultRedisScript使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultRedisScript类属于org.springframework.data.redis.core.script包,在下文中一共展示了DefaultRedisScript类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: releaseLock

import org.springframework.data.redis.core.script.DefaultRedisScript; //导入依赖的package包/类
@Override
public void releaseLock(final String lock, final String holder) {
   Assert.notNull(lock, "Pre-condition violated: lock != null.");
   Assert.notNull(holder, "Pre-condition violated: holder != null.");

   // KEYS[1]: key
   // ARGV[1]: value
   DefaultRedisScript<Void> s = new DefaultRedisScript<>(
         "local lock = redis.call('get', KEYS[1]); " +
         "if (lock == ARGV[1]) then " +
            // We own the lock -> We may release it by deleting the lock.
            "redis.call('del', KEYS[1]); " +
         "end;");

   redis.execute(s, keys(key(LOCK, lock)), value(holder));
}
 
开发者ID:shopping24,项目名称:redjob,代码行数:17,代码来源:LockDaoImpl.java

示例2: tryLock

import org.springframework.data.redis.core.script.DefaultRedisScript; //导入依赖的package包/类
@Override
public boolean tryLock(final String lock, final String holder, final int timeout, final TimeUnit unit) {
   Assert.notNull(lock, "Pre-condition violated: lock != null.");
   Assert.notNull(holder, "Pre-condition violated: holder != null.");
   Assert.isTrue(timeout > 0, "Pre-condition violated: timeout > 0.");
   Assert.notNull(unit, "Pre-condition violated: unit != null.");
   long timeoutMillis = unit.toMillis(timeout);
   Assert.isTrue(timeoutMillis >= 100, "Pre-condition violated: timeoutMillis >= 100.");

   // KEYS[1]: key
   // ARGV[1]: timeout
   // ARGV[2]: value
   DefaultRedisScript<Boolean> s = new DefaultRedisScript<>(
         "local lock = redis.call('get', KEYS[1]); " +
         "if (lock == ARGV[2]) then " +
            // We own the lock -> Refresh expiration.
            "redis.call('pexpire', KEYS[1], ARGV[1]); " +
            "return true; " +
         "end; " +
         "if (lock) then " +
            // Someone else owns the lock -> Abort.
            "return false; " +
         "end; " +
         // No one owns the lock -> Create lock with expiration.
         "redis.call('psetex', KEYS[1], ARGV[1], ARGV[2]); " +
         "return true;",
         Boolean.class);

   return redis.execute(s, keys(key(LOCK, lock)), value(timeoutMillis), value(holder));
}
 
开发者ID:shopping24,项目名称:redjob,代码行数:31,代码来源:LockDaoImpl.java

示例3: redisRequestRateLimiterScript

import org.springframework.data.redis.core.script.DefaultRedisScript; //导入依赖的package包/类
@Bean
@SuppressWarnings("unchecked")
public RedisScript redisRequestRateLimiterScript() {
	DefaultRedisScript redisScript = new DefaultRedisScript<>();
	redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("META-INF/scripts/request_rate_limiter.lua")));
	redisScript.setResultType(List.class);
	return redisScript;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:9,代码来源:GatewayRedisAutoConfiguration.java

示例4: getRedisScript

import org.springframework.data.redis.core.script.DefaultRedisScript; //导入依赖的package包/类
private <T> RedisScript<T> getRedisScript(String script, Class<T> resultType) {
    return new DefaultRedisScript<>(script, resultType);
}
 
开发者ID:soockie,项目名称:sdlock,代码行数:4,代码来源:RedisDependSpringLock.java


注:本文中的org.springframework.data.redis.core.script.DefaultRedisScript类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。