Java Code Examples for org.redisson.api.RedissonClient#getSet()
The following examples show how to use
org.redisson.api.RedissonClient#getSet() .
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: RedissonTopicTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testSyncCommands() throws InterruptedException { RedissonClient redisson = BaseTest.createInstance(); RTopic topic = redisson.getTopic("system_bus"); RSet<String> redissonSet = redisson.getSet("set1"); CountDownLatch latch = new CountDownLatch(1); topic.addListener(String.class, (channel, msg) -> { for (int j = 0; j < 1000; j++) { redissonSet.contains("" + j); } latch.countDown(); }); topic.publish("sometext"); latch.await(); redisson.shutdown(); }
Example 2
Source File: RedisUserTokenManagerTests.java From hsweb-framework with Apache License 2.0 | 5 votes |
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 3
Source File: SetCacheExamples.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(); RSetCache<String> setCache = redisson.getSetCache("mySet"); // with ttl = 20 seconds boolean isAdded = setCache.add("1", 20, TimeUnit.SECONDS); // store value permanently setCache.add("2"); setCache.contains("1"); for (String string : setCache) { // iteration through bulk loaded values } boolean removedValue = setCache.remove("1"); setCache.removeAll(Arrays.asList("1", "2", "3")); setCache.containsAll(Arrays.asList("4", "1", "0")); RSet<String> secondsSet = redisson.getSet("mySecondsSet"); secondsSet.add("4"); secondsSet.add("5"); Set<String> allValues = secondsSet.readAll(); redisson.shutdown(); }
Example 4
Source File: RedissonCodecTest.java From redisson with Apache License 2.0 | 5 votes |
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 5
Source File: SetExamples.java From redisson-examples with Apache License 2.0 | 4 votes |
public static void main(String[] args) { // connects to 127.0.0.1:6379 by default RedissonClient redisson = Redisson.create(); RSet<String> set = redisson.getSet("mySet"); set.add("1"); set.add("2"); set.add("3"); set.contains("1"); for (String string : set) { // iteration through bulk loaded values } boolean removedValue = set.remove("1"); set.removeAll(Arrays.asList("1", "2", "3")); set.containsAll(Arrays.asList("4", "1", "0")); String randomRemovedValue = set.removeRandom(); String randomValue = set.random(); RSet<String> secondsSet = redisson.getSet("mySecondsSet"); secondsSet.add("4"); secondsSet.add("5"); // union with "mySecondsSet" and write it set.union(secondsSet.getName()); // union with "mySecondsSet" without change of set set.readUnion(secondsSet.getName()); // diff with "mySecondsSet" and write it set.diff(secondsSet.getName()); // diff with "mySecondsSet" without change of set set.readDiff(secondsSet.getName()); // intersect with "mySecondsSet" and write it set.intersection(secondsSet.getName()); // intersect with "mySecondsSet" without change of set set.readIntersection(secondsSet.getName()); Set<String> allValues = set.readAll(); redisson.shutdown(); }
Example 6
Source File: RedissonSetTest.java From redisson with Apache License 2.0 | 4 votes |
@Test public void testClusteredIterator() throws FailedToStartRedisException, IOException, InterruptedException { RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave(); RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave(); RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave(); RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave(); RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave(); RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave(); RedisRunner slave4 = new RedisRunner().randomPort().randomDir().nosave(); RedisRunner slave5 = new RedisRunner().randomPort().randomDir().nosave(); RedisRunner slave6 = new RedisRunner().randomPort().randomDir().nosave(); ClusterRunner clusterRunner = new ClusterRunner() .addNode(master1, slave1, slave4) .addNode(master2, slave2, slave5) .addNode(master3, slave3, slave6); ClusterProcesses process = clusterRunner.run(); Config config = new Config(); config.useClusterServers() .setLoadBalancer(new RandomLoadBalancer()) .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort()); RedissonClient redisson = Redisson.create(config); int size = 10000; RSet<String> set = redisson.getSet("test"); for (int i = 0; i < size; i++) { set.add("" + i); } Set<String> keys = new HashSet<>(); for (String key : set) { keys.add(key); } assertThat(keys).hasSize(size); redisson.shutdown(); process.shutdown(); }
Example 7
Source File: RedissionUtils.java From Redis_Learning with Apache License 2.0 | 2 votes |
/** * ��ȡ���� * @param redisson * @param objectName * @return */ public <V> RSet<V> getRSet(RedissonClient redisson,String objectName){ RSet<V> rSet=redisson.getSet(objectName); return rSet; }