How to search for Java objects stored in the Redis

What objects are in Java Live?
Java is an object-oriented programming language, which means that Java is almost no more important than the object concept. The power of distributed objects in Java objects, allowing you to build across multiple processes or distributed computer system.

In Java, active objects (also referred to as active distributed objects) is "enhanced" version of the standard objects. For the active object, an instance reference not only to the Java virtual machine threads, but between different JVM on different machines as well.

a data structure stored the memory redis an open source, commonly used to build a distributed database NoSQL key. To use Java objects in Redis, developers can use RedisJava client, such as Radisson.

In this article, we will discuss how to deal with the theme Redisson Java objects, and how to use Java objects in Redisson search in Redis.

Live Objects Redisson (RLO)
RedissonLiveObjects (RLO) is an object that implements the concept of re-REDIS activities. For rlo, all fields in Java classes are mapped to the hash safflower. This mapping is done by the runtime configuration proxy class.

More specifically, Java classes for each field in the get / set methods are converted into hget / hset method Redis hashes. This allows any client to connect to a Redis server can access RLO.

Use RLO, shared objects as easy as shared objects in a single application across multiple applications and servers. By eliminating the need to handle the serialization and deserialization of, RLO greatly simplifies distributed programming process.

Here is an example of how to use Redisson JavaLiveObject created. Use active objects requires the use of @REntity and @RID comments.

@REntity
2 public class MyObject {
3
4 @RId
5 private String id;
6
7 @RIndex
8 private String field1;
9
10 @RIndex
11 private Integer field2;
12
13 @RIndex
14 private Long field3;
15

Once you have created a rlo and in Redis, you can also use it to store Redisson search for it. Existing search criteria include:

Conditions.eq: "equal" condition attribute value defined limit.
And conditions:. "And" set of conditions for the nested condition.
condition. Or: "OR" condition of a nested set of conditions.
Conditions:. "IN" conditions property is limited to a defined set of values.
Conditions: "greater than" condition property is limited to a defined value.
General Conditions: "greater than or equal to" property conditions defined limit value.
Conditions: The property is limited to a defined value "less than" condition.
Conditions: "is less than or equal to" property conditions defined limit value.
Here is an example of how to search for objects in the Java activity in Redisson. This example will search and find the field 1 = value field <12 all the objects, or field 1 = value and field 2> 2 23 of the object, or an object located within a field range of 3 [1,2].

RLiveObjectService liveObjectService = redisson.getLiveObjectService();
2 liveObjectService.persist(new MyObject());
3
4 Collection objects = liveObjectService.find(MyObject.class,
5 Conditions.or(Conditions.and(Conditions.eq(“field1”, “value”), Conditions.lt(“field2”, 12)),
6 Conditions.and(Conditions.eq(“field1”, “value2”), Conditions.gt(“field2”, 23)),
Conditions.in(“field3”, 1L, 2L));

Redissonpro implemented as a Java object of a search engine Redis, 10 times faster than the open source version, all this reduces the JVM memory consumption. To learn more about the characteristics of redisson pro (including additional features, higher performance, and 24x7 technical support), see Redisson pro website.

Published 849 original articles · won praise 108 · views 80000 +

Guess you like

Origin blog.csdn.net/qf2019/article/details/104769128