Java Code Examples for org.redisson.api.RBucket#set()
The following examples show how to use
org.redisson.api.RBucket#set() .
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: RedissonTransactionalBucketTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testGetAndSet() { RBucket<String> b = redisson.getBucket("test"); b.set("123"); RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults()); RBucket<String> bucket = transaction.getBucket("test"); assertThat(bucket.getAndSet("0")).isEqualTo("123"); assertThat(bucket.get()).isEqualTo("0"); assertThat(bucket.getAndSet("324")).isEqualTo("0"); transaction.commit(); assertThat(redisson.getKeys().count()).isEqualTo(1); assertThat(b.get()).isEqualTo("324"); }
Example 2
Source File: RedissonTransactionalBucketTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testRollback() { RBucket<Object> b = redisson.getBucket("test"); b.set("1234"); RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults()); RBucket<Object> bucket = transaction.getBucket("test"); assertThat(bucket.get()).isEqualTo("1234"); assertThat(bucket.getAndDelete()).isEqualTo("1234"); assertThat(b.get()).isEqualTo("1234"); transaction.rollback(); assertThat(redisson.getKeys().count()).isEqualTo(1); assertThat(b.get()).isEqualTo("1234"); }
Example 3
Source File: CaseController.java From skywalking with Apache License 2.0 | 6 votes |
@RequestMapping("/redisson-case") @ResponseBody public String redissonCase() { RBucket<String> bucket = client.getBucket("key_a"); bucket.set("value_a"); RBatch batch = client.createBatch(); batch.getBucket("batch_k_a").setAsync("batch_v_a"); batch.getBucket("batch_k_b").setAsync("batch_v_b"); batch.getBucket("batch_k_b").expireAsync(20, TimeUnit.SECONDS); batch.execute(); return "Success"; }
Example 4
Source File: RedissonKeysTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testMassDelete() { RBucket<String> bucket0 = redisson.getBucket("test0"); bucket0.set("someValue"); RBucket<String> bucket1 = redisson.getBucket("test1"); bucket1.set("someValue"); RBucket<String> bucket2 = redisson.getBucket("test2"); bucket2.set("someValue"); RBucket<String> bucket3 = redisson.getBucket("test3"); bucket3.set("someValue"); RBucket<String> bucket10 = redisson.getBucket("test10"); bucket10.set("someValue"); RBucket<String> bucket12 = redisson.getBucket("test12"); bucket12.set("someValue"); RMap<String, String> map = redisson.getMap("map2"); map.fastPut("1", "2"); Assert.assertEquals(7, redisson.getKeys().delete("test0", "test1", "test2", "test3", "test10", "test12", "map2")); Assert.assertEquals(0, redisson.getKeys().delete("test0", "test1", "test2", "test3", "test10", "test12", "map2")); }
Example 5
Source File: RedissonKeysTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testDeleteByPattern() { RBucket<String> bucket = redisson.getBucket("test0"); bucket.set("someValue3"); assertThat(bucket.isExists()).isTrue(); RBucket<String> bucket2 = redisson.getBucket("test9"); bucket2.set("someValue4"); assertThat(bucket.isExists()).isTrue(); RMap<String, String> map = redisson.getMap("test2"); map.fastPut("1", "2"); assertThat(map.isExists()).isTrue(); RMap<String, String> map2 = redisson.getMap("test3"); map2.fastPut("1", "5"); assertThat(map2.isExists()).isTrue(); Assert.assertEquals(4, redisson.getKeys().deleteByPattern("test?")); Assert.assertEquals(0, redisson.getKeys().deleteByPattern("test?")); }
Example 6
Source File: ApiAbstract.java From kkbinlog with Apache License 2.0 | 6 votes |
@PostConstruct public void afterPropertiesSet() { ClassPathResource classPathResource = new ClassPathResource("api.json"); try (InputStreamReader reader = new InputStreamReader(classPathResource.getInputStream(),"utf-8")) { StringBuilder api = new StringBuilder(); int tempchar; while ((tempchar = reader.read()) != -1) { api.append((char) tempchar); } String roleResource = api.toString(); if(!StringUtils.isEmpty(roleResource)){ RBucket<Object> bucket = redissonClient.getBucket(clientId.concat("_").concat("resource")); bucket.set(roleResource); logger.info("初始化or更新url资源完成:" + roleResource); } } catch (IOException e) { logger.error("Api抽取上传失败", e); } }
Example 7
Source File: RedissonTransactionalBucketTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testTimeout() throws InterruptedException { RBucket<String> b = redisson.getBucket("test"); b.set("123"); RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults().timeout(3, TimeUnit.SECONDS)); RBucket<String> bucket = transaction.getBucket("test"); bucket.set("234"); Thread.sleep(4000); try { transaction.commit(); Assert.fail(); } catch (TransactionException e) { // skip } Thread.sleep(1000); assertThat(b.get()).isEqualTo("123"); }
Example 8
Source File: AccountServiceImpl.java From Almost-Famous with MIT License | 6 votes |
@Override public Account login(Account account, String clientIp) { account = accountDao.getOne(account); if (Objects.nonNull(account)) { String access_token = TokenGenerator.getToken(account.getUid()); String refreshToken = TokenGenerator.getToken(account.getUid()); accountDao.update(account); RBucket<Object> bucket = redissonClient.getBucket(KeyPrefix.AdminRedisPrefix.ADMIN_USER_ID + account.getUid()); JSONObject jsonObject = new JSONObject(); jsonObject.put("access_token", access_token); jsonObject.put("ip", clientIp); jsonObject.put("refresh_token", refreshToken); jsonObject.put("current_time", System.currentTimeMillis()); jsonObject.put("expire_tick", System.currentTimeMillis() + 1800 * 1000); jsonObject.put("refresh_tick", System.currentTimeMillis() + 600 * 1000); String token = jsonObject.toJSONString(); account.setToken(token); bucket.set(token); } return account; }
Example 9
Source File: DesignElementService.java From mPaaS with Apache License 2.0 | 5 votes |
@Override public String get(String id) { RBucket<String> cache = redisson.getBucket(id, StringCodec.INSTANCE); String result = cache.get(); if (result == null) { Optional<DesignElement> entity = repository.findById(id); if (entity.isPresent()) { result = entity.get().getFdContent(); } else { result = JSON_EMPTY; } cache.set(result, CACHE_EXPIRE_DAY, TimeUnit.DAYS); } return result; }
Example 10
Source File: RedisCache.java From t-io with Apache License 2.0 | 5 votes |
@Override public void putTemporary(String key, Serializable value) { if (StrUtil.isBlank(key)) { return; } RBucket<Serializable> bucket = getBucket(key); bucket.set(value, 10, TimeUnit.SECONDS); }
Example 11
Source File: RedissonTransactionalBucketsTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testGet() { RBucket<String> b = redisson.getBucket("test"); b.set("123"); RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults()); RBuckets buckets = transaction.getBuckets(); assertThat(buckets.get("test").get("test")).isEqualTo("123"); transaction.commit(); assertThat(redisson.getKeys().count()).isEqualTo(1); assertThat(b.get()).isEqualTo("123"); }
Example 12
Source File: RedissionUtilsTest.java From Redis_Learning with Apache License 2.0 | 5 votes |
/** * RBucket ӳ��Ϊ redis server �� string ���� * ֻ�ܴ�����洢��һ���ַ��� * redis server ����: * �鿴���м�---->keys * * �鿴key������--->type testBucket * �鿴key��ֵ ---->get testBucket */ @Test public void testGetRBucket() { RBucket<String> rBucket=RedissionUtils.getInstance().getRBucket(redisson, "testBucket"); //ͬ������ rBucket.set("redisBucketASync"); //�첽���� rBucket.setAsync("����"); String bucketString=rBucket.get(); System.out.println(bucketString); }
Example 13
Source File: RedissonTransactionalBucketTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testSet() { RBucket<String> b = redisson.getBucket("test"); b.set("123"); RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults()); RBucket<String> bucket = transaction.getBucket("test"); bucket.set("234"); assertThat(bucket.get()).isEqualTo("234"); transaction.commit(); assertThat(redisson.getKeys().count()).isEqualTo(1); assertThat(b.get()).isEqualTo("234"); }
Example 14
Source File: RedisCacheTest.java From gcp-token-broker with Apache License 2.0 | 5 votes |
@Test public void testDelete() { // Set a key/value RBucket<byte[]> bucket = client.getBucket("test", ByteArrayCodec.INSTANCE); bucket.set("abcd".getBytes()); // Let the backend delete the key cache.delete("test"); // Check that the key was deleted assertNull(cache.get("test")); assertNull(bucket.get()); }
Example 15
Source File: RedissonObject.java From redisson-spring-boot-starter with GNU Lesser General Public License v3.0 | 5 votes |
/** * 设置对象的值 * * @param name 键 * @param value 值 * @param time 缓存时间 单位毫秒 -1 永久缓存 * @return */ public <T> void setValue(String name, T value, Long time) { RBucket<Object> bucket = redissonClient.getBucket(name); if(time==-1){ bucket.set(value); }else { bucket.set(value, time, TimeUnit.MILLISECONDS); } }
Example 16
Source File: ReferenceExamples.java From redisson-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // connects to 127.0.0.1:6379 by default RedissonClient redisson = Redisson.create(); RMap<String, RBucket<String>> data = redisson.getMap("myMap"); RBucket<String> bs = redisson.getBucket("myObject"); bs.set("5"); bs.set("7"); data.put("bucket", bs); RBucket<String> bucket = data.get("bucket"); }
Example 17
Source File: RedissonKeysTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testRandomKey() { RBucket<String> bucket = redisson.getBucket("test1"); bucket.set("someValue1"); RBucket<String> bucket2 = redisson.getBucket("test2"); bucket2.set("someValue2"); assertThat(redisson.getKeys().randomKey()).isIn("test1", "test2"); redisson.getKeys().delete("test1"); Assert.assertEquals("test2", redisson.getKeys().randomKey()); redisson.getKeys().flushdb(); Assert.assertNull(redisson.getKeys().randomKey()); }
Example 18
Source File: TypedJsonJacksonCodecTest.java From redisson with Apache License 2.0 | 4 votes |
@Test public void testBucket() { RBucket<String> bucket = redisson.getBucket("anyMap", new TypedJsonJacksonCodec(String.class)); bucket.set(String.valueOf("2")); assertThat(bucket.get()).isEqualTo("2"); }
Example 19
Source File: RedisCache.java From gcp-token-broker with Apache License 2.0 | 4 votes |
public void set(String key, byte[] value) { RBucket<byte[]> bucket = getClient().getBucket(key, ByteArrayCodec.INSTANCE); bucket.set(value); }
Example 20
Source File: CacheManager.java From gpmall with Apache License 2.0 | 4 votes |
public void setCache(String key,String val,int expire){ RBucket rBucket = redissonClient.getBucket(key); rBucket.set(val); rBucket.expire(expire, TimeUnit.DAYS); }