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

The following examples show how to use org.redisson.api.RedissonClient#getMap() . 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: RedissonTest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Test
public void test(final MockTracer tracer) {
  final Config config = new Config();
  config.useSingleServer().setAddress("redis://127.0.0.1:6379");

  final RedissonClient redissonClient = Redisson.create(config);
  final RMap<String,String> map = redissonClient.getMap("map");

  map.put("key", "value");
  assertEquals("value", map.get("key"));

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(2, spans.size());

  redissonClient.shutdown();
}
 
Example 2
Source File: NFFTRedisStorage.java    From Panako with GNU Affero General Public License v3.0 6 votes vote down vote up
public NFFTRedisStorage() {
	Config config = new Config();
	config.useSingleServer().setAddress("127.0.0.1:6379");
	//config.useSingleServer().setAddress("157.193.92.74:6379");

	final RedissonClient redisson = Redisson.create(config);
	fingerprintMap = redisson.getMap("integerMap");
	metaDataMap = redisson.getMap("descriptionMap");
	
	secondsStored = redisson.getAtomicLong("secondsStoredAtomicLong");
			
	Runtime.getRuntime().addShutdownHook(new Thread(new Runnable(){
		@Override
		public void run() {
			redisson.shutdown();
		}}));
	
	//rnd = new Random();
}
 
Example 3
Source File: BaseMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testStringCodec() {
    Config config = createConfig();
    config.setCodec(StringCodec.INSTANCE);
    RedissonClient redisson = Redisson.create(config);

    RMap<String, String> rmap = redisson.getMap("TestRMap01");
    rmap.put("A", "1");
    rmap.put("B", "2");

    Iterator<Map.Entry<String, String>> iterator = rmap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, String> next = iterator.next();
        assertThat(next).isIn(new AbstractMap.SimpleEntry("A", "1"), new AbstractMap.SimpleEntry("B", "2"));
    }

    destroy(rmap);
    redisson.shutdown();
}
 
Example 4
Source File: RedissonITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final RedisServer redisServer = new RedisServer();
  TestUtil.retry(new Runnable() {
    @Override
    public void run() {
      redisServer.start();
    }
  }, 10);

  try {
    final Config config = new Config();
    config.useSingleServer().setAddress("redis://127.0.0.1:6379");
    final RedissonClient redissonClient = Redisson.create(config);
    try {
      final RMap<String,String> map = redissonClient.getMap("map");
      map.put("key", "value");
      if (!"value".equals(map.get("key")))
        throw new AssertionError("ERROR: failed to get key value");
    }
    finally {
      redissonClient.shutdown();
    }
  }
  finally {
    redisServer.stop();
    TestUtil.checkSpan(new ComponentSpanCount("java-redis", 2));
    // RedisServer process doesn't exit on 'stop' therefore call System.exit
    System.exit(0);
  }
}
 
Example 5
Source File: TracingRedissonTest.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void test_config_span_name() throws Exception {
  Config config = new Config();
  config.useSingleServer().setAddress("redis://127.0.0.1:6379");

  RedissonClient customClient = new TracingRedissonClient(Redisson.create(config),
      new TracingConfiguration.Builder(tracer)
          .traceWithActiveSpanOnly(true)
          .withSpanNameProvider(operation -> "Redis." + operation)
          .build());

  final MockSpan parent = tracer.buildSpan("test").start();
  try (Scope ignore = tracer.activateSpan(parent)) {
    RMap<String, String> map = customClient.getMap("map_config_span_name");
    map.getAsync("key").get(15, TimeUnit.SECONDS);
  }
  parent.finish();

  await().atMost(15, TimeUnit.SECONDS).until(reportedSpansSize(), equalTo(2));

  List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(2, spans.size());
  MockSpan redisSpan = spans.get(0);
  assertEquals("Redis.getAsync", redisSpan.operationName());

  assertNull(tracer.activeSpan());
  customClient.shutdown();
}
 
Example 6
Source File: RedisUserTokenManagerTests.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
        RedissonClient client = Redisson.create();

        try {
            ConcurrentMap<String, SimpleUserToken> repo = client.getMap("hsweb.user-token", new SerializationCodec());
            ConcurrentMap<String, Set<String>> userRepo = client.getMap("hsweb.user-token-u", new SerializationCodec());

            userTokenManager = new DefaultUserTokenManager(repo, userRepo) {
                @Override
                protected Set<String> getUserToken(String userId) {
                    userRepo.computeIfAbsent(userId,u->new HashSet<>());

                    return client.getSet("hsweb.user-token-"+userId, new SerializationCodec());
                }

            };

            userTokenManager.setAllopatricLoginMode(AllopatricLoginMode.deny);
//            userTokenManager=new DefaultUserTokenManager();


//            userRepo.clear();
//            repo.clear();
//            for (int i = 0; i < 1000; i++) {
//                userTokenManager.signIn(IDGenerator.MD5.generate(), "sessionId", "admin", 60*3600*1000);
//            }
//            userTokenManager.signIn(IDGenerator.MD5.generate(), "sessionId", "admin2", 60*3600*1000);

            testGet();
            testGetAll();
            testSignOut();

            testGetAll();
        } finally {
            client.shutdown();
        }
    }
 
Example 7
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 8
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 9
Source File: SSLExamples.java    From redisson-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    Config config = new Config();

    // rediss - defines to use SSL for Redis connection
    config.useSingleServer().setAddress("rediss://127.0.0.1:6379");
    RedissonClient redisson = Redisson.create(config);

    RMap<String, String> map = redisson.getMap("test");
    map.put("mykey", "myvalue");
    String value =  map.get("mykey");
    
    redisson.shutdown();
}
 
Example 10
Source File: RedissonCodecTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testListOfStrings() {
    Config config = createConfig();
    config.setCodec(new JsonJacksonCodec());
    RedissonClient redisson = Redisson.create(config);

    RMap<String, List<String>> map = redisson.getMap("list of strings", jsonListOfStringCodec);
    map.put("foo", new ArrayList<String>(Arrays.asList("bar")));

    RMap<String, List<String>> map2 = redisson.getMap("list of strings", jsonListOfStringCodec);

    assertThat(map2).isEqualTo(map);
    
    redisson.shutdown();
}
 
Example 11
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 12
Source File: RedisMapWrapper.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
protected RMap<byte[], byte[]> initSyncCollection(
    final RedissonClient client,
    final String setName,
    final Codec codec) {
  return client.getMap(setName, codec);
}
 
Example 13
Source File: MapReduceExample.java    From redisson-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    redisson.getExecutorService(RExecutorService.MAPREDUCE_NAME).registerWorkers(WorkerOptions.defaults().workers(3));
    
    RMap<String, String> map = redisson.getMap("myMap");
    
    map.put("1", "Alice was beginning to get very tired"); 
    map.put("2", "of sitting by her sister on the bank and");
    map.put("3", "of having nothing to do once or twice she");
    map.put("4", "had peeped into the book her sister was reading");
    map.put("5", "but it had no pictures or conversations in it");
    map.put("6", "and what is the use of a book");
    map.put("7", "thought Alice without pictures or conversation");
    
    Map<String, Integer> result = new HashMap<>();
    result.put("to", 2);
    result.put("Alice", 2);
    result.put("get", 1);
    result.put("beginning", 1);
    result.put("sitting", 1);
    result.put("do", 1);
    result.put("by", 1);
    result.put("or", 3);
    result.put("into", 1);
    result.put("sister", 2);
    result.put("on", 1);
    result.put("a", 1);
    result.put("without", 1);
    result.put("and", 2);
    result.put("once", 1);
    result.put("twice", 1);
    result.put("she", 1);
    result.put("had", 2);
    result.put("reading", 1);
    result.put("but", 1);
    result.put("it", 2);
    result.put("no", 1);
    result.put("in", 1);
    result.put("what", 1);
    result.put("use", 1);
    result.put("thought", 1);
    result.put("conversation", 1);
    result.put("was", 2);
    result.put("very", 1);
    result.put("tired", 1);
    result.put("of", 3);
    result.put("her", 2);
    result.put("the", 3);
    result.put("bank", 1);
    result.put("having", 1);
    result.put("nothing", 1);
    result.put("peeped", 1);
    result.put("book", 2);
    result.put("pictures", 2);
    result.put("conversations", 1);
    result.put("is", 1);
    
    RMapReduce<String, String, String, Integer> mapReduce = map
                .<String, Integer>mapReduce()
                .mapper(new WordMapper())
                .reducer(new WordReducer());
    
    Integer count = mapReduce.execute(new WordCollator());
    System.out.println("Count " + count);
    
    Map<String, Integer> resultMap = mapReduce.execute();
    System.out.println("Result " + resultMap);
}
 
Example 14
Source File: RedissionUtils.java    From Redis_Learning with Apache License 2.0 2 votes vote down vote up
/** 
 * ��ȡMap���� 
 * @param redisson 
 * @param objectName 
 * @return 
 */  
public <K,V> RMap<K, V> getRMap(RedissonClient redisson,String objectName){  
    RMap<K, V> map=redisson.getMap(objectName);  
    return map;  
}