当前位置: 首页>>代码示例>>Java>>正文


Java RedissonClient类代码示例

本文整理汇总了Java中org.redisson.api.RedissonClient的典型用法代码示例。如果您正苦于以下问题:Java RedissonClient类的具体用法?Java RedissonClient怎么用?Java RedissonClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RedissonClient类属于org.redisson.api包,在下文中一共展示了RedissonClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mapsLocalCache2

import org.redisson.api.RedissonClient; //导入依赖的package包/类
void mapsLocalCache2(Waiter waiter) {
    Config config = new Config();
    config.useSingleServer().setAddress("http://127.0.0.1:6379");
    RedissonClient client = Redisson.create(config);

    LocalCachedMapOptions options = LocalCachedMapOptions.defaults().maxIdle(10 * 1000).timeToLive(10 * 1000);
    RLocalCachedMap<String, Integer> map = client.getLocalCachedMap("myMap", options);

    System.out.println("KEY BEFORE: " + map.get("key"));

    try {
        Thread.sleep(2000);
    }
    catch(InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("KEY AFTER: " + map.get("key"));
    waiter.assertEquals(map.get("key"), 25);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:20,代码来源:RedisTest.java

示例2: createInstance

import org.redisson.api.RedissonClient; //导入依赖的package包/类
@Override
    public RedissonClient createInstance(int connections, String host) {
        Config c = new Config();
//        c.setUseLinuxNativeEpoll(true);
//        c.useClusterServers()
        c.useSingleServer()
        .setTimeout(10000000)
        .setAddress(host)
        .setConnectionPoolSize(connections).setConnectionMinimumIdleSize(connections);
//        .addNodeAddress(host)
//        .setMasterConnectionPoolSize(connections).setMasterConnectionMinimumIdleSize(connections);
        c.setCodec(StringCodec.INSTANCE);

        RedissonClient r = Redisson.create(c);
        r.getKeys().flushdb();
        return r;
    }
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:18,代码来源:RedissonBench.java

示例3: mapsItemChange2

import org.redisson.api.RedissonClient; //导入依赖的package包/类
void mapsItemChange2(Waiter waiter){
    Config config = new Config();
    config.useSingleServer().setAddress("http://127.0.0.1:6379");
    RedissonClient client = Redisson.create(config);

    LocalCachedMapOptions options = LocalCachedMapOptions.defaults().maxIdle(10 * 1000).timeToLive(10 * 1000);
    RLocalCachedMap<String, FinalValue<Integer>> map = client.getLocalCachedMap("myMap", options);
    FinalValue<Integer> value = map.get("test");
    System.out.println("Value Before: " + value.get());

    try {
        Thread.sleep(2000);
    }
    catch(InterruptedException e) {
        e.printStackTrace();
    }

    value = map.get("test");
    System.out.println("Value After: " + value.get());
    waiter.assertEquals(value.get(), 18);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:22,代码来源:RedisTest.java

示例4: provider

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static RedissonClient provider() {
    if (client == null) {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + REDIS_HOST + ":6379");
        client = Redisson.create(config);
    }
    return client;
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:9,代码来源:JungleStorageFactory.java

示例5: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    Bench<RedissonClient> bench = new RedissonBench() {
        @Override
        public void executeOperation(String data, RedissonClient benchInstance, int threadNumber, int iteration,
                MetricRegistry metrics) {
            RList<String> list = benchInstance.getList("list_" + threadNumber);

            Timer.Context time = metrics.timer("list").time();
            list.add(data);
            time.stop();
        }
    };
    
    Benchmark benchmark = new Benchmark(bench);
    benchmark.run(args);
}
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:17,代码来源:ListAddBenchmark.java

示例6: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
        Config config = new Config();
        config.useSingleServer().setAddress("127.0.0.1:6379");
        RedissonClient redisson = Redisson.create(config);
        Messager messager = new RedissonMessager(redisson);

        byte[] stat = new byte[1];

//        new Thread(() -> {
//            for (int i = 0; i < 1000; i++) {
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                messager.publish(text("hello2"))
//                        .to(topic("test"))
//                        .from(user("admin"))
//                        .send();
//            }
//        }).start();
        messager.subscribe(topic("test"))
                .onMessage(System.out::println)
                .onMessage(msg -> stat[0] = 1);
        //redisson.shutdown();
    }
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:27,代码来源:RedissonMessagerTest.java

示例7: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RSortedSet<String> sortedSet = redisson.getSortedSet("mySortedSet");
    sortedSet.add("1");
    sortedSet.add("2");
    sortedSet.add("3");
    
    for (String string : sortedSet) {
        // iteration through bulk loaded values
    }
    
    String firstValue = sortedSet.first();
    String lastValue = sortedSet.last();
    
    boolean removedValue = sortedSet.remove("1");
    sortedSet.removeAll(Arrays.asList("1", "2", "3"));
    sortedSet.containsAll(Arrays.asList("4", "1", "0"));
    
    redisson.shutdown();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:23,代码来源:SortedSetExamples.java

示例8: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
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();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:17,代码来源:BucketExamples.java

示例9: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RLock lock = redisson.getLock("lock");
    lock.lock(2, TimeUnit.SECONDS);

    Thread t = new Thread() {
        public void run() {
            RLock lock1 = redisson.getLock("lock");
            lock1.lock();
            lock1.unlock();
        };
    };

    t.start();
    t.join();

    lock.unlock();
    
    redisson.shutdown();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:23,代码来源:LockExamples.java

示例10: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    RHyperLogLog<String> hyperLogLog = redisson.getHyperLogLog("hyperLogLog");
    hyperLogLog.add("1");
    hyperLogLog.add("2");
    hyperLogLog.add("3");
    hyperLogLog.addAll(Arrays.asList("10", "20", "30"));
    
    RHyperLogLog<String> hyperLogLog1 = redisson.getHyperLogLog("hyperLogLog1");
    hyperLogLog1.add("4");
    hyperLogLog1.add("5");
    hyperLogLog1.add("6");
    
    RHyperLogLog<String> hyperLogLog2 = redisson.getHyperLogLog("hyperLogLog2");
    hyperLogLog1.add("4");
    hyperLogLog1.add("5");
    hyperLogLog1.add("6");
    
    hyperLogLog2.mergeWith(hyperLogLog1.getName());
    hyperLogLog2.countWith(hyperLogLog1.getName());

    redisson.shutdown();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:26,代码来源:HyperLogLogExamples.java

示例11: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    CountDownLatch latch = new CountDownLatch(1);
    
    RTopic<String> topic = redisson.getTopic("topic2");
    topic.addListener(new MessageListener<String>() {
        @Override
        public void onMessage(String channel, String msg) {
            latch.countDown();
        }
    });
    
    topic.publish("msg");
    latch.await();
    
    redisson.shutdown();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:20,代码来源:TopicExamples.java

示例12: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
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();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:18,代码来源:BucketExamples.java

示例13: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    RAtomicLong atomicLong = redisson.getAtomicLong("myLong");
    atomicLong.getAndDecrement();
    atomicLong.getAndIncrement();
    
    atomicLong.addAndGet(10L);
    atomicLong.compareAndSet(29, 412);
    
    atomicLong.decrementAndGet();
    atomicLong.incrementAndGet();
    
    atomicLong.getAndAdd(302);
    atomicLong.getAndDecrement();
    atomicLong.getAndIncrement();
    
    redisson.shutdown();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:21,代码来源:AtomicLongExamples.java

示例14: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    RAtomicDouble atomicDouble = redisson.getAtomicDouble("myDouble");
    atomicDouble.getAndDecrement();
    atomicDouble.getAndIncrement();
    
    atomicDouble.addAndGet(10.323);
    atomicDouble.compareAndSet(29.4, 412.91);
    
    atomicDouble.decrementAndGet();
    atomicDouble.incrementAndGet();
    
    atomicDouble.getAndAdd(302.00);
    atomicDouble.getAndDecrement();
    atomicDouble.getAndIncrement();
    
    redisson.shutdown();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:21,代码来源:AtomicDoubleExamples.java

示例15: main

import org.redisson.api.RedissonClient; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    RBinaryStream stream = redisson.getBinaryStream("myStream");
    
    byte[] values = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
    stream.trySet(values);
    stream.set(values);
    
    InputStream is = stream.getInputStream();
    StringBuilder sb = new StringBuilder();
    int ch;
    while((ch = is.read()) != -1) {
        sb.append((char)ch);
    }
    String str = sb.toString();
    
    OutputStream os = stream.getOutputStream();
    for (int i = 0; i < values.length; i++) {
        byte c = values[i];
        os.write(c);
    }
    
    redisson.shutdown();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:27,代码来源:BinaryStreamExamples.java


注:本文中的org.redisson.api.RedissonClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。