DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Writing DTOs With Java8, Lombok, and Java14+
  • Redefining Java Object Equality
  • Addressing Memory Issues and Optimizing Code for Efficiency: Glide Case
  • Singleton: 6 Ways To Write and Use in Java Programming

Trending

  • AI’s Role in Everyday Development
  • Streamlining Event Data in Event-Driven Ansible
  • Agentic AI for Automated Application Security and Vulnerability Management
  • How Trustworthy Is Big Data?
  1. DZone
  2. Coding
  3. Languages
  4. How to Search for Java Objects Stored in Redis

How to Search for Java Objects Stored in Redis

In this article, we’ll discuss how Redisson treats the topic of Java objects, and how you can use Redisson to search for Java objects in Redis.

By 
Nikita Koksharov user avatar
Nikita Koksharov
·
Feb. 26, 20 · Analysis
Likes (6)
Comment
Save
Tweet
Share
25.6K Views

Join the DZone community and get the full member experience.

Join For Free

What Is a Live Object in Java?

Java is an object-oriented programming language, which means there are few concepts more important in Java than objects. The power of objects in Java is enhanced with distributed objects, which enable you to build distributed systems across multiple processes or computers.

In Java, a live object (also known as a live distributed object) is an “enhanced” version of a standard object. With live objects, instance references can be shared not only between Java Virtual Machine (JVM) threads but also between different JVMs on different machines.

Redis is an open-source in-memory data structure store that is often used to build distributed NoSQL key-value databases. To use Java objects with Redis, developers make use of Redis Java clients such as Redisson.

You may also like: All About Object in Java

In this article, we’ll discuss how Redisson treats the topic of Java objects, and how you can use Redisson to search for Java objects in Redis.

Redisson Live Objects (RLOs)

Redisson Live Objects (RLOs) are a reimplementation of the concept of live objects for Redis. With an RLO, all the fields inside a Java class are mapped to a Redis hash. This mapping is done by a proxy class constructed at runtime.

More specifically, the get/set methods of each field in the Java class are translated into hget/hset methods in the Redis hash. This makes the RLO accessible to any client connected to the Redis server.

With RLOs, sharing objects between multiple applications and servers is just as easy as sharing them within a single application. By removing the need to handle serialization and deserialization, RLOs dramatically simplify the process of distributed programming.

Searching for Java Objects in Redis With Redisson

Below is an example of how to create a Java live object with Redisson. The @REntity and @RId annotations are required to use live objects.

Java
x
16
 
1
@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
  
16
}


Once you’ve created an RLO and stored it in Redis, you can also search for it using Redisson. The search conditions available include:

  • Conditions.eq: "EQUALS" condition restricting a property to a defined value.
  • Conditions.and: "AND" condition for a collection of nested conditions.
  • Conditions.or: "OR" condition for a collection of nested conditions.
  • Conditions.in: "IN" condition restricting a property to a set of defined values.
  • Conditions.gt: "GREATER THAN" condition restricting a property to a defined value.
  • Conditions.ge: "GREATER THAN OR EQUAL" condition restricting a property to a defined value.
  • Conditions.lt: "LESS THAN" condition restricting a property to a defined value.
  • Conditions.le: "LESS THAN OR EQUAL" condition restricting a property to a defined value.

Below is an example of how to search for Java live objects in Redisson. This example search will find all objects where field1 = value and field2 < 12, or where field1 = value and field2 > 23, or where field3 is in the range [1, 2].

Java
xxxxxxxxxx
1
 
1
RLiveObjectService liveObjectService = redisson.getLiveObjectService();
2
liveObjectService.persist(new MyObject());
3
 
          
4
Collection<MyObject> 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)), 
7
     Conditions.in("field3", 1L, 2L));
8
 
          


Redisson PRO implements a Redis search engine for Java objects that’s up to 10 times faster than the open-source version, all while lowering JVM memory consumption. To learn more about the features of Redisson PRO—including additional features, higher performance, and 24x7 technical support — check out the Redisson PRO website.


Further Reading

5 Different Ways to Create Objects in Java

Java Immutable Objects

What's Wrong With Small Objects in Java?

Object (computer science) Java (programming language) Redis (company)

Opinions expressed by DZone contributors are their own.

Related

  • Writing DTOs With Java8, Lombok, and Java14+
  • Redefining Java Object Equality
  • Addressing Memory Issues and Optimizing Code for Efficiency: Glide Case
  • Singleton: 6 Ways To Write and Use in Java Programming

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!