Java Code Examples for org.redisson.api.RMap#fastPut()

The following examples show how to use org.redisson.api.RMap#fastPut() . 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: RedissionUtilsTest.java    From Redis_Learning with Apache License 2.0 6 votes vote down vote up
/** 
 * RMap  ӳ��Ϊ  redis server �� hash ���� 
 * ��Ϊ 
 * put(���ؼ�ֵ) �� fast(����״̬) 
 * ͬ��    �첽 
 * redis server ����: 
 * �鿴���м�---->keys * 
 * �鿴key������--->type testMap 
 * �鿴key��ֵ ---->hgetall testMap 
 * @throws InterruptedException 
 * @throws ExecutionException 
 */  
@Test  
public void testGetRMap() throws InterruptedException, ExecutionException {  
    RMap<String, Integer> rMap=RedissionUtils.getInstance().getRMap(redisson, "testMap");  
    //�������  
    rMap.clear();  
    //���key-value ����֮ǰ��������ֵ  
    Integer firrtInteger=rMap.put("111", 111);  
    System.out.println(firrtInteger);  
    //���key-value ����֮ǰ��������ֵ  
    Integer secondInteger=rMap.putIfAbsent("222", 222);  
    System.out.println(secondInteger);  
    //�Ƴ�key-value  
    Integer thirdInteger=rMap.remove("222");  
    System.out.println(thirdInteger);  
    //���key-value ������֮ǰ��������ֵ  
    boolean third=rMap.fastPut("333", 333);  
    System.out.println(third);   
    //��������  
    for(String key :rMap.keySet()){  
        System.out.println(key+":"+rMap.get(key));  
    }  
      
}
 
Example 2
Source File: BaseMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriterFastPut() {
    Map<String, String> store = new HashMap<>();
    RMap<String, String> map = getWriterTestMap("test", store);

    map.fastPut("1", "11");
    map.fastPut("2", "22");
    map.fastPut("3", "33");
    
    Map<String, String> expected = new HashMap<>();
    expected.put("1", "11");
    expected.put("2", "22");
    expected.put("3", "33");
    assertThat(store).isEqualTo(expected);
    destroy(map);
}
 
Example 3
Source File: RedissonKeysTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: RedissonKeysTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteByPatternBatch() {
    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();


    RBatch batch = redisson.createBatch();
    batch.getKeys().deleteByPatternAsync("test?");
    BatchResult<?> r = batch.execute();
    Assert.assertEquals(4L, r.getResponses().get(0));
}
 
Example 5
Source File: RedissonKeysTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: MapExamples.java    From redisson-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RMap<String, Integer> map =  redisson.getMap("myMap");
    map.put("a", 1);
    map.put("b", 2);
    map.put("c", 3);
    
    boolean contains = map.containsKey("a");
    
    Integer value = map.get("c");
    Integer updatedValue = map.addAndGet("a", 32);
    
    Integer valueSize = map.valueSize("c");
    
    Set<String> keys = new HashSet<String>();
    keys.add("a");
    keys.add("b");
    keys.add("c");
    Map<String, Integer> mapSlice = map.getAll(keys);
    
    // use read* methods to fetch all objects
    Set<String> allKeys = map.readAllKeySet();
    Collection<Integer> allValues = map.readAllValues();
    Set<Entry<String, Integer>> allEntries = map.readAllEntrySet();
    
    // use fast* methods when previous value is not required
    boolean isNewKey = map.fastPut("a", 100);
    boolean isNewKeyPut = map.fastPutIfAbsent("d", 33);
    long removedAmount = map.fastRemove("b");
    
    redisson.shutdown();
}
 
Example 7
Source File: RedissonObjectBuilder.java    From redisson with Apache License 2.0 5 votes vote down vote up
public void store(RObject ar, String fieldName, RMap<String, Object> liveMap) {
    Codec codec = ar.getCodec();
    if (codec != null) {
        codecProvider.registerCodec((Class) codec.getClass(), codec);
    }
    liveMap.fastPut(fieldName,
            new RedissonReference(ar.getClass(), ar.getName(), codec));
}
 
Example 8
Source File: RedissonCodecTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
public void test(RedissonClient redisson) {
    RMap<Integer, Map<String, Object>> map = redisson.getMap("getAll");
    Map<String, Object> a = new HashMap<String, Object>();
    a.put("double", new Double(100000.0));
    a.put("float", 100.0f);
    a.put("int", 100);
    a.put("long", 10000000000L);
    a.put("boolt", true);
    a.put("boolf", false);
    a.put("string", "testString");
    a.put("array", new ArrayList<Object>(Arrays.asList(1, 2.0, "adsfasdfsdf")));

    map.fastPut(1, a);
    Map<String, Object> resa = map.get(1);
    Assert.assertEquals(a, resa);

    Set<TestObject> set = redisson.getSet("set");

    set.add(new TestObject("1", "2"));
    set.add(new TestObject("1", "2"));
    set.add(new TestObject("2", "3"));
    set.add(new TestObject("3", "4"));
    set.add(new TestObject("5", "6"));

    Assert.assertTrue(set.contains(new TestObject("2", "3")));
    Assert.assertTrue(set.contains(new TestObject("1", "2")));
    Assert.assertFalse(set.contains(new TestObject("1", "9")));
    
    redisson.shutdown();
}
 
Example 9
Source File: RedissonKeysTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindKeys() {
    RBucket<String> bucket = redisson.getBucket("test1");
    bucket.set("someValue");
    RMap<String, String> map = redisson.getMap("test2");
    map.fastPut("1", "2");

    Iterable<String> keys = redisson.getKeys().getKeysByPattern("test?");
    assertThat(keys).containsOnly("test1", "test2");

    Iterable<String> keys2 = redisson.getKeys().getKeysByPattern("test");
    assertThat(keys2).isEmpty();
}