-
Notifications
You must be signed in to change notification settings - Fork 233
Kundera over Redis
Devender Yadav edited this page Mar 23, 2017
·
4 revisions
Redis is an open-source, networked, in-memory, key-value data store. Redis provides support for following data types:
- String
- List of string
- Set of string
- Sorted set of string
- HashSet of string
As a JPA provider, Kundera provides support for Redis. It allows to perform CRUD and query operation over Redis in JPA way. Let's look into how to use Kundera over Redis as a database.
- Entity
*/
@Entity
@Table(name = "PERSON", schema = "RedisK@redis_pu")
public class PersonRedis
{
/** The person id. */
@Id
@Column(name = "PERSON_ID")
private String personId;
/** The person name. */
@Column(name = "PERSON_NAME")
private String personName;
/** The age. */
@Column(name = "AGE")
private Integer age;
// setters and getters.
}
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
https://raw.github.com/impetus-opensource/Kundera/Kundera-2.0.4/kundera-core/src/test/resources/META-INF/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="redis_pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="6379" />
<property name="kundera.keyspace" value="RedisK" />
<property name="kundera.dialect" value="redis" />
<property name="kundera.client" value="redis" />
<property name="kundera.client.lookup.class" value="com.impetus.client.redis.RedisClientFactory" />
<property name="kundera.cache.provider.class"
value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
</properties>
</persistence-unit>
</persistence>
- Authentication
We can enable authentication over redis server for all client operation as:
<property name="kundera.password" value="Kundera@123" /> {look into redis.conf for requirePass value}
- Transaction
To enable transaction support over Redis, we simply need to provide:
<property name="kundera.transaction.resource.class" value="com.impetus.client.redis.RedisTransaction" />
To configure transaction timeout and connection pool size over Redis connection we need to :
<property name="kundera.transaction.timeout" value="30" />
<property name="kundera.pool.size.max.active" value="10" />
- Please refer RedisTransactionTest for usage for JPA transaction test.
EntityManagerFactory emf = Persistence.createEntityManagerFactory("redis_pu");
EntityManager em = emf.createEntityManager();
//create object.
final String originalName = "vivek";
PersonRedis object = new PersonRedis();
object.setAge(32);
object.setPersonId(ROW_KEY);
object.setPersonName(originalName);
em.persist(object); // persist object.
PersonRedis result = (PersonRedis) em.find(PersonRedis.class, ROW_KEY);
- Find by key
EntityManagerFactory emf = Persistence.createEntityManagerFactory("redis_pu");
EntityManager em = emf.createEntityManager();
// find by key.
String findById = "Select p from PersonRedis p where p.personId=:personId";
Query query = em.createQuery(findById);
query.setParameter("personId", ROW_KEY);
results = query.getResultList();
- Find by key and now row key
// Find by key and now row key
EntityManagerFactory emf = Persistence.createEntityManagerFactory("redis_pu");
EntityManager em = emf.createEntityManager();
String findByAge = "Select p from PersonRedis p where p.age=:age";
Query query = em.createQuery(findByAge);
query.setParameter("age", 32);
results = query.getResultList();
- Between clause
// Between clause over rowkey
String findIdByBetween = "Select p from PersonRedis p where p.personId between :min AND :max";
query = em.createQuery(findIdByBetween);
query.setParameter("min", ROW_KEY);
query.setParameter("max", ROW_KEY + 1);
results = query.getResultList();
- Please refer RedisQueryTest for more details over JPA query support.
You may also refer junits for more examples.
Kundera relies on HashSet for storing entity and builds inverted indexes of non-key fields and store them as Sorted set to provide JPQL support over non-key fields.
-
Datastores Supported
- Releases
-
Architecture
-
Concepts
-
Getting Started in 5 minutes
-
Features
- Object Mapper
- Polyglot Persistence
- Queries Support
- JPQL (JPA Query Language)
- Native Queries
- Batch insert update
- Schema Generation
- Primary Key Auto generation
- Transaction Management
- REST Based Access
- Geospatial Persistence and Queries
- Graph Database Support
-
Composite Keys
-
No hard annotation for schema
-
Support for Mapped superclass
-
Object to NoSQL Data Mapping
-
Cassandra's User Defined Types and Indexes on Collections
-
Support for aggregation
- Scalar Queries over Cassandra
- Connection pooling using Kundera Cassandra
- Configuration
-
Kundera with Couchdb
-
Kundera with Elasticsearch
-
Kundera with HBase
-
Kundera with Kudu
-
Kundera with RethinkDB
-
Kundera with MongoDB
-
Kundera with OracleNoSQL
-
Kundera with Redis
-
Kundera with Spark
-
Extend Kundera
- Sample Codes and Examples
-
Blogs and Articles
-
Tutorials
* Kundera with Openshift
* Kundera with Play Framework
* Kundera with GWT
* Kundera with JBoss
* Kundera with Spring
-
Performance
-
Troubleshooting
-
FAQ
- Production deployments
- Feedback