Java Code Examples for org.redisson.api.RedissonClient#getBucket()

The following examples show how to use org.redisson.api.RedissonClient#getBucket() . 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: BucketExamples.java    From redisson-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    RedissonClient redisson = Redisson.create();
    
    RBucket<String> bucket = redisson.getBucket("test");
    bucket.set("123");
    boolean isUpdated = bucket.compareAndSet("123", "4934");
    String prevObject = bucket.getAndSet("321");
    boolean isSet = bucket.trySet("901");
    long objectSize = bucket.size();
    
    // set with expiration
    bucket.set("value", 10, TimeUnit.SECONDS);
    boolean isNewSet = bucket.trySet("nextValue", 10, TimeUnit.SECONDS);
    
    redisson.shutdown();
}
 
Example 2
Source File: BucketExamples.java    From redisson-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RBucket<String> bucket = redisson.getBucket("test");
    bucket.set("123");
    boolean isUpdated = bucket.compareAndSet("123", "4934");
    String prevObject = bucket.getAndSet("321");
    boolean isSet = bucket.trySet("901");
    long objectSize = bucket.size();
    
    // set with expiration
    bucket.set("value", 10, TimeUnit.SECONDS);
    boolean isNewSet = bucket.trySet("nextValue", 10, TimeUnit.SECONDS);
    
    redisson.shutdown();
}
 
Example 3
Source File: TransactionExamples.java    From redisson-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RBucket<String> b = redisson.getBucket("test");
    b.set("123");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucket<String> bucket = transaction.getBucket("test");
    bucket.set("234");
    
    RMap<String, String> map = transaction.getMap("myMap");
    map.put("1", "2");
    
    transaction.commit();
}
 
Example 4
Source File: ReferenceExamples.java    From redisson-examples with Apache License 2.0 5 votes vote down vote up
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 5
Source File: RedissonCodecTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testAvro() throws IOException {
    AvroMapper am = new AvroMapper();
    AvroSchema schema = am.schemaFor(TestObject.class);
    Codec avroCodec = new AvroJacksonCodec(TestObject.class, schema);
    
    Config config = createConfig();
    config.setCodec(avroCodec);
    RedissonClient redisson = Redisson.create(config);

    RBucket<TestObject> b = redisson.getBucket("bucket");
    b.set(new TestObject("1", "2"));
    
    assertThat(b.get()).isEqualTo(new TestObject("1", "2"));
}
 
Example 6
Source File: ScriptExamples.java    From redisson-examples with Apache License 2.0 3 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    RBucket<String> bucket = redisson.getBucket("foo");
    bucket.set("bar");

    RScript script = redisson.getScript(StringCodec.INSTANCE);

    // execute script in read only mode
    String result = script.eval(RScript.Mode.READ_ONLY,
                           "return redis.call('get', 'foo')", 
                           RScript.ReturnType.VALUE);


    
    // execute the same script stored in Redis lua script cache

    // load lua script into Redis cache to all redis master instances
    String sha1 = script.scriptLoad("return redis.call('get', 'foo')");

    // call lua script by sha digest
    result = redisson.getScript().evalSha(RScript.Mode.READ_ONLY,
                                sha1, RScript.ReturnType.VALUE, Collections.emptyList());
    
    
    redisson.shutdown();
}
 
Example 7
Source File: RedissionUtils.java    From Redis_Learning with Apache License 2.0 2 votes vote down vote up
/** 
 * ��ȡ�ַ������� 
 * @param redisson 
 * @param t 
 * @param objectName 
 * @return 
 */  
public <T> RBucket<T> getRBucket(RedissonClient redisson,String objectName){  
    RBucket<T> bucket=redisson.getBucket(objectName);  
    return bucket;  
}