Redisson examples
redisson / redisson-examples Goto Github PK
View Code? Open in Web Editor NEWRedisson java examples
License: Apache License 2.0
Redisson java examples
License: Apache License 2.0
Hi,
I very happy to find this repo of some example of redisson.
I try to save date as object in redisson but i can't, in your examples i see an objectexample but not work,
Thank
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)
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?
Redisson Version: Redisson 3.14.0
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());
}
}
There is an error problem
Lambda expressions are allowed only at source level 1.8 or above
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!
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!
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
` 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?
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?
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?
Hello,
I have done a sample project for testing the integration with redisson/spring boot/spring session/spring security. (https://github.com/DevWantJustHaveFun/spring-boot-session-redisson)
Do you think it could be useful to add it to this repository ?
If yes I can make a pull request, if no you can close this issue
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?
License header is missing in the following classes,
ReferenceExamples.java, StreamExamples.java, TransactionExamples.java.
When i run the demo, exception happens
private Map<String, Integer> itemName2Amount; (nullpointer)
Can you provide some examples of using reactive
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)
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.