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


Java BoundValueOperations类代码示例

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


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

示例1: setUp

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    Map<String, BoundValueOperations> map = Maps.newHashMap();
    Map<String, Long> longMap = Maps.newHashMap();
    when(redisTemplate.boundValueOps(any())).thenAnswer(invocation -> {
        String key = invocation.getArgument(0);
        BoundValueOperations mock = map.computeIfAbsent(key, k -> Mockito.mock(BoundValueOperations.class));
        when(mock.increment(anyLong())).thenAnswer(invocationOnMock -> {
            long value = invocationOnMock.getArgument(0);
            return longMap.compute(key, (k, v) -> ((v != null) ? v : 0L) + value);
        });
        return mock;
    });
    target = new RedisRateLimiter(rateLimiterErrorHandler, redisTemplate);
}
 
开发者ID:marcosbarbero,项目名称:spring-cloud-zuul-ratelimit,代码行数:17,代码来源:RedisRateLimiterTest.java

示例2: saveSecurityContext

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
private void saveSecurityContext(HttpServletRequest request, HttpServletResponse response, SecurityContext context){
	String sid = getSessionId(request);
	if(StringUtils.isBlank(sid)){
		SaveToSessionResponseWrapper responseWrapper = WebUtils.getNativeResponse(response, SaveToSessionResponseWrapper.class);
		sid = responseWrapper.getSid();
		saveSessionCookies(request, response, sid);
	}
	
	LoginUserDetails loginUser = SecurityUtils.getCurrentLoginUser(context);
	if(loginUser!=null){
		loginUser.setToken(sid);
	}
	
	BoundValueOperations<String, SecurityContext> bondOps = getSessionBoundOps(sid);
	//当前spring-data-redis版本不支持setex,分成两个操作
	bondOps.set(context);
	setSecurityContextExpireTime(request);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:19,代码来源:RedisSecurityContextRepository.java

示例3: testBoundOperations

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
/**
     * BoundKeyOperations、BoundValueOperations、BoundSetOperations
     * BoundListOperations、BoundSetOperations、BoundHashOperations
     */
    @Test
    public void testBoundOperations() {
        BoundValueOperations<String, Object> boundValueOperations = redisTemplate.boundValueOps("BoundTest");
        //设置值
//        boundValueOperations.set("test12345");
        //设置过期时间
//        boundValueOperations.expire(100, TimeUnit.SECONDS);
        //重命名Key
//        boundValueOperations.rename("BoundTest123");
    
        System.out.println("key: " + boundValueOperations.getKey());
        System.out.println(boundValueOperations.get());
        System.out.println("expire: " + boundValueOperations.getExpire());
    }
 
开发者ID:alamby,项目名称:upgradeToy,代码行数:19,代码来源:RedisTest.java

示例4: counterIncrease

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
public void counterIncrease(String key, Integer i, Long expSec)
{
    Preconditions.checkArgument(StringUtils.isNotEmpty(key), "key is empty");
    Preconditions.checkNotNull(i, "counterIncrease num is null");

    BoundValueOperations<String, Object> b = redisTemplate.boundValueOps(key);
    b.increment(i);
    if(expSec != null && b.getExpire() != null)
    {
        redisTemplate.expire(key, expSec, TimeUnit.SECONDS);
    }
}
 
开发者ID:slking1987,项目名称:mafia,代码行数:13,代码来源:RedisUtil.java

示例5: counterGet

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
public Long counterGet(String key)
{
    Preconditions.checkArgument(StringUtils.isNotEmpty(key), "key is empty");

    BoundValueOperations<String, Object> b = redisTemplate.boundValueOps(key);
    Object val = b.get(0, -1);
    return val == null ? null : Long.valueOf((String)val);
}
 
开发者ID:slking1987,项目名称:mafia,代码行数:9,代码来源:RedisUtil.java

示例6: store

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
/**
 * 保存到redis
 *
 * @param key  唯一标示
 * @param ttl  失效时长(单位:秒)
 * @param type 事件类型
 */
public void store(Serializable key, int ttl, RedisEventType type) {
    Assert.notNull(key, "key不能为空!");
    Assert.notNull(type, "type不能为空!");

    if (ttl <= 0) {
        // 抛出事件
        publishEvent(new RedisEvent(this, key, type));
        return;
    }

    BoundValueOperations<String, Object> operations = redisTemplate.boundValueOps(REDIS_KEY_PREFIX + type.getType() + REDIS_KEY_SEPARATOR + key);
    operations.set(key, ttl * 1000, TimeUnit.MILLISECONDS);
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:21,代码来源:RedisTimerListener.java

示例7: testRateLimitExceedCapacity

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
@Test
@Override
@SuppressWarnings("unchecked")
public void testRateLimitExceedCapacity() throws Exception {
    BoundValueOperations ops = mock(BoundValueOperations.class);
    when(this.redisTemplate.boundValueOps(anyString())).thenReturn(ops);
    when(ops.increment(anyLong())).thenReturn(3L);
    super.testRateLimitExceedCapacity();
}
 
开发者ID:marcosbarbero,项目名称:spring-cloud-zuul-ratelimit,代码行数:10,代码来源:RedisRateLimitPreFilterTest.java

示例8: testRateLimit

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
@Test
@Override
@SuppressWarnings("unchecked")
public void testRateLimit() throws Exception {
    BoundValueOperations ops = mock(BoundValueOperations.class);
    when(this.redisTemplate.boundValueOps(anyString())).thenReturn(ops);
    when(ops.increment(anyLong())).thenReturn(2L);


    this.request.setRequestURI("/serviceA");
    this.request.setRemoteAddr("10.0.0.100");

    assertTrue(this.filter.shouldFilter());

    for (int i = 0; i < 2; i++) {
        this.filter.run();
    }

    String key = "null_serviceA_serviceA_10.0.0.100_anonymous";
    String remaining = this.response.getHeader(RateLimitPreFilter.REMAINING_HEADER + key);
    assertEquals("0", remaining);

    TimeUnit.SECONDS.sleep(2);

    when(ops.increment(anyLong())).thenReturn(1L);
    this.filter.run();
    remaining = this.response.getHeader(RateLimitPreFilter.REMAINING_HEADER + key);
    assertEquals("1", remaining);
}
 
开发者ID:marcosbarbero,项目名称:spring-cloud-zuul-ratelimit,代码行数:30,代码来源:RedisRateLimitPreFilterTest.java

示例9: get

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
private long get(BoundValueOperations valueOperations) {
    Object value = valueOperations.get();
    if (value == null) {
        return 0;
    }
    if (value instanceof Number) {
        return ((Number) value).longValue();
    }
    if (value instanceof String) {
        return StringUtils.isEmpty(value) ? 0 : Long.parseLong(value.toString());
    }
    return 0;
}
 
开发者ID:blackshadowwalker,项目名称:spring-distributelock,代码行数:14,代码来源:RedisLock.java

示例10: addOps

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
protected void addOps(final EmailSchedulingData emailSchedulingData) {
    final String orderingKey = orderingKey(emailSchedulingData);
    final String valueKey = emailSchedulingData.getId();

    final double score = calculateScore(emailSchedulingData);

    BoundZSetOperations<String, String> orderingZSetOps = orderingTemplate.boundZSetOps(orderingKey);
    orderingZSetOps.add(valueKey, score);
    orderingZSetOps.persist();

    BoundValueOperations<String, EmailSchedulingData> valueValueOps = valueTemplate.boundValueOps(valueKey);
    valueValueOps.set(emailSchedulingData);
    valueValueOps.persist();
}
 
开发者ID:ozimov,项目名称:spring-boot-email-tools,代码行数:15,代码来源:DefaultPersistenceService.java

示例11: setSecurityContextExpireTime

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
private void setSecurityContextExpireTime(HttpServletRequest request){
	String sid = getSessionId(request);
	if(StringUtils.isBlank(sid))
		return ;
	BoundValueOperations<String, SecurityContext> bondOps = getSessionBoundOps(sid);
	int invalidTime = request.getSession().getMaxInactiveInterval();
	bondOps.expire(invalidTime, TimeUnit.SECONDS);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:9,代码来源:RedisSecurityContextRepository.java

示例12: boundValueOps

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
@Override
public BoundValueOperations<K, V> boundValueOps(K key) {
	try {
		return redisTemplate.boundValueOps(key);
	} catch (Exception ex) {
		throw new RedisBaoException(ex);
	}
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:9,代码来源:RedisBaoSupporter.java

示例13: main

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	JedisShardInfo jedisShardInfo1 = new JedisShardInfo(ip1);
	jedisShardInfo1.setPassword(JedisConstant.password);
	JedisShardInfo jedisShardInfo2 = new JedisShardInfo(ip2);
	jedisShardInfo2.setPassword(JedisConstant.password);

	List<JedisShardInfo> jedisShardInfos = new ArrayList<JedisShardInfo>();
	jedisShardInfos.add(jedisShardInfo1);
	jedisShardInfos.add(jedisShardInfo2);

	JedisPoolConfig poolConfig = new JedisPoolConfig();
	poolConfig.setMaxActive(JedisConstant.maxActive);
	poolConfig.setMaxIdle(JedisConstant.maxIdle);
	poolConfig.setMaxWait(JedisConstant.maxWait);
	poolConfig.setTestOnBorrow(JedisConstant.testOnBorrow);
	poolConfig.setTestOnReturn(JedisConstant.testOnReturn);


	ShardedJedisPool shardedJedisPool = new ShardedJedisPool(poolConfig, jedisShardInfos);

	JedisConnectionFactory factory = new JedisConnectionFactory(jedisShardInfo1);
	StringRedisTemplate template = new StringRedisTemplate(factory);
	for (int i = 0; i < 2000; i++) {
		String key = "howsun_" + i;
		BoundValueOperations<String, String> v = template.boundValueOps(key);
		//jedis.set(key, UUID.randomUUID().toString());
		System.out.println(key + "\t" + v.get() + "\t" + factory.getHostName());
	}

}
 
开发者ID:howsun,项目名称:howsun-javaee-framework,代码行数:34,代码来源:SpringDataRedis.java

示例14: boundValueOps

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
@Override
public BoundValueOperations<K, V> boundValueOps(K key) {
	throw new MethodNotSupportException("myRedisTemplate not support this method : boundValueOps(K key) , please use opsForXX");
	//return new DefaultBoundValueOperations<K, V>(key, this);
}
 
开发者ID:mauersu,项目名称:redis-admin,代码行数:6,代码来源:MyRedisTemplate.java

示例15: getOps

import org.springframework.data.redis.core.BoundValueOperations; //导入依赖的package包/类
protected EmailSchedulingData getOps(final String id) {
    //valueTemplate.
    BoundValueOperations<String, EmailSchedulingData> boundValueOps = valueTemplate.boundValueOps(id);
    EmailSchedulingData emailSchedulingData = boundValueOps.get();
    return emailSchedulingData;
}
 
开发者ID:ozimov,项目名称:spring-boot-email-tools,代码行数:7,代码来源:DefaultPersistenceService.java


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