Giter Site home page Giter Site logo

redisson-examples's Introduction

redisson-examples

Redisson examples

redisson-examples's People

Contributors

jackygurui avatar mrniko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redisson-examples's Issues

Can not catch InterruptedException

public static void main(String[] args) throws InterruptedException {
    // connects to 127.0.0.1:6379 by default
    Config config = new Config();
    config.useSingleServer().setAddress("redis://192.168.99.100:6379");
    RedissonClient redisson = Redisson.create(config);

    RBlockingQueue<String> queue = redisson.getBlockingQueue("myQueue");

    Thread t = new Thread(() -> {
        try {

// String element = queue.take(10, TimeUnit.SECONDS);
String secondElement = queue.take();
} catch (InterruptedException e) {
System.out.println("InterruptedException");
e.printStackTrace();
}
});
t.start();
TimeUnit.SECONDS.sleep(3);
t.interrupt();

    TimeUnit.SECONDS.sleep(3);
    redisson.shutdown();
}

The output is as below:
Exception in thread "Thread-1" org.redisson.client.RedisException: Unexpected exception while processing command
at org.redisson.command.CommandAsyncService.convertException(CommandAsyncService.java:400)
at org.redisson.command.CommandAsyncService.get(CommandAsyncService.java:204)
at org.redisson.RedissonObject.get(RedissonObject.java:94)
at org.redisson.RedissonBlockingQueue.take(RedissonBlockingQueue.java:80)
at org.redisson.example.collections.BlockingQueueInterruptedExamples.lambda$main$0(BlockingQueueInterruptedExamples.java:42)
at java.lang.Thread.run(Thread.java:748)

Any PubSub examples?

I'm looking into possibly replacing my http POST based REST/Api Servlet (that's being used as a mechanism to communicate with my Java application from other non-java applications) with redis PubSub.

Are there any example of how to use Redisson for subscribing/consuming messages that external apps would publish to?

Would love to see a few examples for the Async flavors of Collections

Love the examples in this repo, but it would be helpful if there were some updated examples for the asynchronous flavors of Collections (i.e. RMapAsync/RSetAsync).

For example, this is deprecated now, and it isn't super clear what the updated way of calling this would be now:

public void addRedisUser(final User user, final boolean retry) {
    try {
        RMapAsync<Long, User> localRedisUsers = redissonClient.getMap("myUserMap");

        // the "addListener" here is deprecated (RFuture<V> addListener(FutureListener<? super V> listener))
        // but not clear on how else to do this
        localRedisUsers.fastPutAsync(user.getUserId(), user).addListener(future -> {
            if (future.isSuccess()) {
                // the result of the future is true for user didn't exist and was added
                // and false if the key existed and user was updated
                if (future.getNow()) {
                    // add to stats
                    ServerStats.addToDailyUniqueUserSet(user.getUserId());
                }
            } else {
                // an error has occurred, so try again if we have the retry flag
                // don't want to call with retry again so we avoid getting stuck in a loop
                if (retry) {
                    addRedisUser(user, false);
                    ServerStats.redisAddUserRetries.incrementAndGet();
                } else {
                    ServerStats.redisAddUserFails.incrementAndGet();
                }

                throw new Exception(
                    "addRedisUser fastPutAsync failed for user: " + user.toString(),
                    future.cause()
                );
            }
        });
    } catch (Exception e) {
        logger.warn("Exception caught in addRedisUser: {}", e.getMessage());
    }
}

Can't used in jdk7

There is an error problem
Lambda expressions are allowed only at source level 1.8 or above

[Question] Redisson behaviour if a shard is down

Hi

In a redis cluster if a shard is down and hence redisson client is not able to make connections to it then would application experience higher latency (=connection timeout) for each of the calls to that shard
OR
redisson client would intelligently fail the request immediately for that particular shard and keep retrying to make the connection in background ?

Thanks!

[Question] Redisson behaviour if primary of a shard is down

Hi

In a redis cluster with 1 secondary node in each shard what is the behaviour if primary node is network partitioned from the client ? Consider redisson driver is configured with ReadMode.MASTER_SLAVE.

Will redisson driver 'sense' it and start sending all the read traffic to the corresponding secondary ?

Thanks!

Error in org.redisson.example.services.ExecutorServiceExamples

When I try ExecutorServiceExamples, I get following error message :

java.lang.IllegalArgumentException: java.io.IOException: java.lang.RuntimeException: Class org.redisson.example.services.ExecutorServiceExamples$RunnableTask does not implement Serializable or externalizable
at org.redisson.RedissonExecutorService.encode(RedissonExecutorService.java:375)
at org.redisson.RedissonExecutorService.execute(RedissonExecutorService.java:325)
at org.redisson.example.services.ExecutorServiceExamples.main(ExecutorServiceExamples.java:73)
(and more)

I'm using JDK 1.8.0_121, and use the Redis cluster in another machine.

Can someone tell me the requirements to make this example pass ? Thanks.

=。=!~

使用RList尝试存放对象时,序列化获取的泛型有问题
127.0.0.1:6379> LRANGE ******** 0 3

  1. "{"@Class":"************Control$1","endTime":["java.util.Date",1509093480980],"numberCount":5,
    "startTime":["java.util.Date",1509093480980],"times":100}"

i have a problem about RLocalCachedMap

` RLocalCachedMap<String, Integer> cachedMap = redisson.getLocalCachedMap("myMap", options);
cachedMap.put("a", 1);
cachedMap.put("b", 2);
cachedMap.put("c", 3);

    boolean contains = cachedMap.containsKey("a");
    
    Integer value = cachedMap.get("c");
    Integer updatedValue = cachedMap.addAndGet("a", 32);
 
`
    But while executing the last line, an error occurred:ERR hash value is not a valid float . channel: [id: 0xcf1b13e4, L:/127.0.0.1:55203 - R:127.0.0.1/127.0.0.1:6379] command: (EVAL), promise: java.util.concurrent.CompletableFuture@121574fb[Not completed, 1 dependents], params: [local result = redis.call('HINCRBYFLOAT', KEYS[1], ARGV[1], ARGV[2]); if ARGV[3] == '1' then redis.call('publish', KEYS[2], ARGV[4]); end;if ARGV[3] == '2' then redis.call('zadd', KEYS[3], ARGV[5], ARGV[6]);redis.call('publish', KEYS[2], ARGV[4]); end;return result; , 3, myMap, {myMap}:topic, redisson__cache_updates_log:{myMap}, PooledUnsafeDirectByteBuf(ridx: 0, widx: 3, cap: 256), 32.0, 1, PooledUnsafeDirectByteBuf(ridx: 0, widx: 37, cap: 256), 1711590785540, ...]
    how to resolve?

How to keep Thread variables in jmeter when multiple Threads are running in parallel?

I have my multiple threads Running in parallel. Any request can get fired from any thread that too multiple times. I have stored my request variables in beanshell using vars.put(). I have retrieved this variables in another beanshell using vars.get(). but when Thread runs in parallel , I want that while retriving a variable it should retrive the value which of current Thread. Somewhat like in java how we use this keyword and get current object's property. how can I do this?

Is There a Way to Retrieve a Hash/Map Along With Its Key?

Hello,

Is there a means by which one can execute a batch call to retrieve a batch of hashes along with the keys that identify each hash?

For example:

key1 -> {"Name" "Tom" "Age" 29}
key2 -> {"Name" "Jerry" "Age" 30}

How can one retrieve both the hash and its key (key1, key2, etc.) in the same (batch) request?

[Question] Interrupting a running thread and stopping its execution

I've a situation where I need to terminate previously running tasks before starting a new one. I've tried to use the cancel(taskId) method but it cancels a task that is scheduled to run not a currently running task.

Is there a method to kill the task currently executing?

Error in LockExample.java

Description

Run the code snippet in cluster mode, with Spring Boot. Got the following error.

java.lang.IllegalMonitorStateException: attempt to unlock lock, not locked by current thread by node id: c4ba59b1-154e-4e09-926f-010044f547f9 thread-id: 1

	at org.redisson.RedissonLock.lambda$unlockAsync$3(RedissonLock.java:605)

Possible reason

The Lock is acquired and released by the lock1 object after t.join in. lock.unlock() line 46 will cause such error as the lock is no longer be acquired by the lock object.

Proposed changes

Remove lock.unlock() at line 46, as the lock acquired by the lock object is expired automatically after 2 seconds. And lock1 will release the lock in line 37. The final unlock action is redundant and will cause errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.