顾睿2

What is Redisson?

Redisson is a Redis Java library that provides distributed Java objects and services including Set, Multimap, SortedSet, Map, List, Queue, BlockingQueue, Deque, BlockingDeque, Semaphore, Lock, AtomicLong, CountDownLatch, Publish / Subscribe, Bloom filter, Remote service, Spring cache, Executor service, Live Object service and most recently added Scheduled executor service on top of the Redis server.

What is a Live Object?

A Live Object can be understood as an enhanced version of standard Java object, of which an instance reference can be shared not only between threads in a single JVM, but can also be shared between different JVMs across different machines. Wikipedia discribes it as:

Live distributed object (also abbreviated as live object) refers to a running instance of a distributed multi-party (or peer-to-peer) protocol, viewed from the object-oriented perspective, as an entity that has a distinct identity, may encapsulate internal state and threads of execution, and that exhibits a well-defined externally visible behavior.

How Redisson Live Object Works

Redisson Live Object (RLO) realized this idea by mapping all the fields inside a Java class to a Redis hash through a runtime-constructed proxy class. All the get/set methods of each field are translated to hget/hset commands operated on the Redis hash, making it accessable to/from any clients connected to the same Redis server. As we all know, the field values of an object represent its state; having them stored in a remote repository, Redis, makes it a distributed object. This object is a Redisson Live Object.

What Benefits Does it Have Over a Standard Java Object?

This process provides a range of benefit over standard Java objects. Traditionally, when multiple threads access a shared object, the reference of the object is then passed to each of them. This model is fine for standalone applications, but it's not possible to share the object between applications and/or servers in a distributed environment. For those types of use cases, we would have to serialize the object, transmit it to the other end and deserialize it back to an object. It is often the case that the entire object has to be serialized and transmitted even just one field is modified. This process not only adds performance overhead to the application, it also complicates the programming model: A serialized object is detached from its original, so changes to the state of the object which happen after serialisation are not visible to the other end.

By using RLO, sharing an object between applications and/or servers is the same as sharing one in a standalone application. This removes the need for serialization and deserialization, and at the same time reduces the complexity of the programming model: Changes made to one field is (almost^) immediately accessable to other processes, applications and servers. (^Redis' eventual consistant replication rule still applies when connected to slave nodes)

Since the Redis server is a single-threaded application, all field access to the live object is automatically executed in atomic fashion: a value will not be changed when you are reading it.

With Redisson Live Object, you can treat the redis server as a shared Heap space for all connected JVMs.

How is a Live Object Different Than a Standard Java Object?

Due to the fact that the state of the object is kept in Redis instead of in the local JVM, there are a few differences compared to using standard Java objects, and they need to be taken into consideration when architecting a system that employs this feature.

As described above, in a Redisson Live Object, changes to its fields are immediately made available to other processes and JVMs. This in effect makes all fields in the object volatile.

What Kind of Application Can Benefit From It?

Redisson Live Object can prove itself to be useful in many domains and fields. It can assist developers in easily creating team-collabrating systems, such as a whiteboard, mobile game matchmaking, cross device copy-and-paste like you've seen in the upcoming iOS 10, and many others.

It can be used to improve availability of a system or service while reducing the complexity of its implementation. Having critical system states and/or configurations stored as live objects in a redis cluster, the system can survive from node crashes without complicated logic to achieve background state syncing and config validating upon reviving. This is extremely useful for mission critical systems in the Oil and Gas industry, Energy industry, Banking/Finance industry, and many more.

It can also be used to manage the state of swarms of connected devices. By connecting multiple devices together to a shared live object, we can easily make dumb switches and devices into a smart connected self-aware network.

While the Redisson Live Object seems incredibly useful on its own, with careful design and engineering, it can be used to create some features which are even greater. By combining it with Redisson Remote Service, we can create applications that can be paused, fast-forwarded and even rewound and replayed on demand. By constructing all the application states as live objects, you can kill all running process and have the application "Paused"; Or simply run multiple copies of the same application on multiple nodes to reduce the load on each individual node and/or increase the overall performance of the system. This effectively makes the system go "Fast-forward"; Or you can keep snapshots of all the live objects every so often, while keeping all the changes tracked in a log, you can have the application go back in time, relive a moment in the past and replay all the changes as you wish. This is making the system "Rewind and Replay". It's like elastic computing happening at the application level.

How Does it Differ From Other Live Objects?

Redisson Live Object was designed and developed by Rui Gu overseen by Nikita Koksharov. The idea was inspired originally by the Java JPA API since both the RDBMs and redis are centralized services and used as data repositories. It was initially called "Attached Object" since its behavior was somewhat similar to the JPA entity object inside a JPA transaction.

Nikita Koksharov suggested the name "Live Object" and we both think it is more appropriate for the final shape of the feature than "Attached Object".

Knowing the evolution of this feature, it is understandable that while sharing the same Live Object design pattern with solutions from other projects, Redisson Live Object works differently internally to those solutions in a few ways. Redisson Live Object uses redis as its data storage, all changes to the object are translated as redis commands and operated on a given redis hash. The local JVM does not hold any value in the fields of the object except for the field that represents the key name of the hash. Other solutions are focussed on retaining a local copy of the object at each JVM and transmitting all the changes to the object over a shared pub/sub channel to each other participant. It is obvious that the solution used for Redisson Live Objects is superior compared with the solutions from other projects. While other solutions have employed complicated mechanisms to guarantee each participant receives and reflects all the changes in same order, Redisson naturally inherits this guarantee from redis because it is a single-threaded centralised service. Commands sent to it are always processed in a first-come, first-served manner. Because the Redisson Live Object keeps its state in a remote repository, the state can be retained even after all of the participants go offline, whereas other solutions require at least one participant to stay online at any time to ensure the state of the objects are not lost.

Usage

In order to enjoy all the benefits brought by Redisson Live Object, only thing you need to do is annotate the Class you desire to use with @REntity, then annotate a field with @RId.

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">@REntity</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">public class MyLiveObject {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> @RId</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> private String name;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> //other fields</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> ...</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> ...</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> //getters and setters</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> ...</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> ...</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">}</pre>

Now you have made an otherwise standard Java object class into a Redisson Live Object class. You are able to get an instance of it with the RedissonLiveObjectService, which you can get from a RedissonClient.

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">...</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">RLiveObjectService service = redisson.getLiveObjectService();</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyLiveObject myObject1 = service.<MyLiveObject, String>getOrCreate(MyLiveObject.class, "myObjectId");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">...</pre>

Using the Redisson Live Object is the same as using a standard Java object. Let's assume you have this object:

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">@REntity</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">public class MyObject {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> @RId</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> private String name;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> private String value;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public MyObject(String name) {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> this.name = name;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public MyObject() {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public String getName() {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> return name;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public String getValue() {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> return value;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public void setName(String name) {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> this.name = name;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public void setValue(String value) {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> this.value = value;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">}</pre>

Somewhere else in the code you may want to create it as a standard Java instance.

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Standard Java object instance</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyObject standardObject1 = new MyObject();</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">standardObject1.setName("standard1");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Of course you can use non-default constructor</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyObject standardObject2 = new MyObject("standard2");</pre>

Elsewhere, you may also want to create it as a Redisson Live Object instance:

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//first create the service</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">RLiveObjectService service = redisson.getLiveObjectService();</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//instantiate the object with the service</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyObject liveObject1 = service.<MyObject, String>getOrCreate(MyObject.class, "liveObjectId");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Behind scense, it tries to locate the constructor with one argument and invoke with the id value, </pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//"liveObjectId" in this case. If the constructor is not found, falls back on default constructor</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//and then call setName("liveObjectId") before returns back to you.</pre>

There is literally no difference when it comes to using these instances:

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Setting the "value" field is the same</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">standardObject1.setValue("abc");//the value "abc" is stored in heapspace in VM</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">standardObject2.setValue("abc");//same as above</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">liveObject1.setValue("abc");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//the value "abc" is stored inside redis, no value is stored in heap. (OK, there</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//is a string pool, but the value is not referenced here in the object, so it can</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//be garbage collected.)</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Getting the "value" out is just the same</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(standardObject1.getValue());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//It should give you "abc" in the console, the value is retrieved from heapspace in the VM;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(standardObject2.getValue());//same as above.</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(liveObject1.getValue());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//output is the same as above, but the value is retrieved from redis.</pre>

While these two snippets of code look exactly the same, there is a slight difference between them. Let me explain it with another example:

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">@REntity</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">public class MyLiveObject {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> @RId</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> private String name;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> private MyOtherObject value;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public MyLiveObject(String name) {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> this.name = name;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public MyObject() {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public String getName() {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> return name;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public MyOtherObject getValue() {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> return value;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public void setName(String name) {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> this.name = name;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> public void setValue(MyOtherObject value) {</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> this.value = value;</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;"> }</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">}</pre>

In this case, the type of the "value" field is a mutable type. In a standard Java object, when you invoke the getValue()method, the reference to this MyOtherObject instance is returned to you. When you invoke the same method on a Redisson Live Object, a reference of a new instance is returned. This can have the following two effects:

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Redisson Live Object behaviour:</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyLiveObject myLiveObject = service.getOrCreate(MyLiveObject.class, "1");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">myLiveObject.setValue(new MyOtherObject());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue() == myLiveObject.getValue());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//False (unless you use a custom Codec with object pooling)</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Standard Java Object behaviour:</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyLiveObject notLiveObject = new MyLiveObject();</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">notLiveObject.setValue(new MyOtherObject());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(notLiveObject.getValue() == notLiveObject.getValue());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//True</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Redisson Live Object behaviour:</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyLiveObject myLiveObject = service.getOrCreate(MyLiveObject.class, "1");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyOtherObject other = new MyOtherObject();</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">other.setOtherName("ABC");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">myLiveObject.setValue(other);</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue().getOtherName());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//ABC</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">other.setOtherName("BCD");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue().getOtherName());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//still ABC</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">myLiveObject.setValue(other);</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue().getOtherName());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//now it's BCD</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Standard Java Object behaviour:</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyLiveObject myLiveObject = service.getOrCreate(MyLiveObject.class, "1");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyOtherObject other = new MyOtherObject();</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">other.setOtherName("ABC");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">myLiveObject.setValue(other);</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue().getOtherName());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//ABC</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">other.setOtherName("BCD");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue().getOtherName());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//already is BCD</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">myLiveObject.setValue(other);</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue().getOtherName());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//still is BCD</pre>

The reason for this difference in behavior is because we are not keeping any of the object states, and each setter and getter call will serialize and deserialize the value to and from Redis back to a local VM. This effectively detaches the field value from the object state. This behavior is usually not a problem when the value type is an immutable type, such as String, Double, Long, etc. When you are dealing with a mutable type, you may want to benefit from this behaviour, since the value instance is detached off from the object state, you can consider all the read/write actions to this value instance is effectively in a transaction with ACID property. It can be extremely useful when the application is designed to incorporate this behavior properly. If you prefer to stick to standard Java behavior, you can always convert the MyOtherObject into a Redisson Live Object.

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//Redisson Live Object with nested Redisson Live Object behaviour:</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyLiveObject myLiveObject = service.getOrCreate(MyLiveObject.class, "1");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">MyOtherObject other = service.getOrCreate(MyOtherObject.class, "2");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">other.setOtherName("ABC");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">myLiveObject.setValue(other);</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue().getOtherName());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//ABC</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">other.setOtherName("BCD");</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue().getOtherName());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//you see, already is BCD </pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">myLiveObject.setValue(other);</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">System.out.println(myLiveObject.getValue().getOtherName());</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">//and again still is BCD</pre>

Field types in the Redisson Live Object can be almost anything, from Java util classes to collection/map types and of course your own custom objects, as long as it can be encoded and decoded by a supplied codec. More details about the codec can be found in the Advanced Usage section.

As much as I like to say it's free with no limits, there are still some restrictions on the choices of field types you can have. The field annotated with RId can not be an array type, i.e. int[], long[], double[], byte[], etc. More details and explainations can be found in Restrictions section

In order to keep Redisson Live Objects behaving as closely to standard Java objects as possible, Redisson automatically converts the following standard Java field types to its counter types supported by Redisson RObject.

STANDARD JAVA CLASS CONVERTED REDISSON CLASS
SortedSet.class RedissonSortedSet.class
Set.class RedissonSet.class
ConcurrentMap.class RedissonMap.class
Map.class RedissonMap.class
BlockingDeque.class RedissonBlockingDeque.class
Deque.class RedissonDeque.class
BlockingQueue.class RedissonBlockingQueue.class
Queue.class RedissonQueue.class
List.class RedissonList.class

The conversion prefers the one nearer to the top of the table if a field type matches more than one entries. i.e. LinkedList implements Deque, List, Queue, it will be converted to a RedissonDeque because of this.

Instances of these Redisson classes retains their states, values, and entries in Redis too, changes to them are directly reflected into Redis without keeping values in local VM.

Advanced Usage

As described before, Redisson Live Object classes are proxy classes which can be fabricated when needed and then get cached in a RedissonClient instance against its original class. This process can be a bit slow and it is recommended to pre-register all the Redisson Live Object classes via RedissonLiveObjectService for any kind of delay-sensitive applications. The service can also be used to unregister a class if it is no longer needed. And of course it can be used to check if the class has already been registered.

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">RLiveObjectService service = redisson.getLiveObjectService();</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">service.registerClass(MyClass.class);</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">service.unregisterClass(MyClass.class);</pre>

<pre style="box-sizing: border-box; overflow: visible; font-family: monospace; font-size: 13px; display: block; padding: 0px 4px; margin: 0px; line-height: inherit; word-break: break-all; overflow-wrap: normal; color: inherit; background: transparent; border: 0px solid rgb(204, 204, 204); border-radius: 0px; white-space: pre; z-index: 2; position: relative; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual;">Boolean registered = service.isClassRegistered(MyClass.class);</pre>

@REntity

The behaviour of each type of Redisson Live Object can be customised through properties of the @REntity annotation. You can specify each of those properties to gain fine control over its behaviour.

  • namingScheme - You can specify a naming scheme which tells Redisson how to assign key names for each instance of this class. It is used to create a reference to an existing Redisson Live Object and materialising a new one in redis. It defaults to use Redisson provided DefaultNamingScheme.
  • codec - You can tell Redisson which Codec class you want to use for the Redisson Live Object. Redisson will use an instance pool to locate the instance based on the class type. It defaults to JsonJacksonCodec provided by Redisson.
  • fieldTransformation - You can also specify a field transformation mode for the Redisson Live Object. As mentioned before, in order to keep everything as close to standard Java as possible, Redisson will automatically transform fields with commonly-used Java util classes to Redisson compatible classes. This uses ANNOTATION_BASED as the default value. You can set it to IMPLEMENTATION_BASED which will skip the transformation.

@RId

The @RId annotation is used on a field that can be used to distinguish between one instance and another. Think of this field as the primary key field of this class. The value of this field is used to create a reference to existing Redisson Live Object. The field with this annotation is the only field that has its value also kept in the local VM. You can only have one RId annotation per class.

You can supply a generator strategy to the @RId annotation if you want the value of this field to be programatically generated. The default generator is RandomUUIDIdStringGenerator which generates a v4(Random) UUID string when used.

@RObjectField

When the transformationMode in @REntity is set to ANNOTATION_BASED, which is the default value, you can optionally use it to annotate a field that does not have @RId annotation at the same time. This is often used to give a different namingScheme and/or a different codec class to the ones specified in @REntity.

As you can see the codec and namingScheme are quite often used in providing a Redisson Live Object and its service, in order to reduce the amount of redundant instances. Redisson, by default, caches these instances internally to be reused. You can supply your own providers for each of them via Redisson's Config instance.

Restrictions

At the moment, Redisson Live Objects can only be classes with the default constructor or classes with a single-argument constructor, and the argument is assumed to be used as the value for field with RId annotaion. As mentioned above, the type of the RId field cannot be an Array type. This is due to the DefaultNamingScheme which cannot serialize and deserialize the Array type as of yet. This restriction can be lifted once the DefaultNamingScheme is improved. Since the RId field is encoded as part of the key name used by the underlying RMap, it makes no sense to create a RLO with just have one field. It is better to use a RBucket for this type of usage.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,884评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,755评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,369评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,799评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,910评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,096评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,159评论 3 411
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,917评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,360评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,673评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,814评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,509评论 4 334
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,156评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,882评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,123评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,641评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,728评论 2 351

推荐阅读更多精彩内容

  • 英子 1924年的冬天。 冷风呼啸着奔过田野来到村庄。 一家农院的外墙下,一个小婴儿安静的睡着了。凛冽的寒风间,整...
    偏爱荒度的光阴阅读 152评论 1 1
  • 天空还是那么的蓝啊,刚从自己简易青石床上起来的冬青,又一次发出了这样的感叹,越发觉得自己当初的选择没有错。 穿着一...
    青春如野马阅读 206评论 0 1
  • 生锈的指针 不住的咿呀 这里的深夜 还有生命 你那的夜 是否还有安静
    马桶上不看书阅读 124评论 0 0
  • 滤镜效果大家肯定都知道,毕竟现在相机这么牛,一般都有这个功能。不废话,开搞! 所谓滤镜效果,就是对一张图像的颜色进...
    其勇勇阅读 508评论 0 1