Redis at NOSQL Playground

NOSQL is a movement is around for long time ago but since 2009 is getting stronger and more consistency. Relation data based have they place and they always will have BUT besides the scalability that in some scenarios is more a matter of cost in other Relations Databases is really the wrong choice not just because scalability BUT is a matter of design and complexity X simplicity.

The Right structure have a huge impact on the complexity/simplicity of the code and design and have said that this maybe or may not create performance issues. Is a common sens that Relational Databases have beens overused in this last 3 decades.

There a debate about the name, my take on that is that is not only SQL and you must consider different databases or data structures in your solution toolbox.


NOSQL Ecosystem

The most common kinds of NOSQL databases are:

  • Document Store
  • Key Value Store
  • Graph Store
  • Tabular Store

CAP

According to CAP Theorem you have: Availability,  Consistency and Partition Tolerance. You can't have 3 you must pick both. Nathan Hurst create a very interesting visual CAP diagram with NOSQL ecosystem.






























As you can see in the Nathan Diagram Redis in more on the AP(Availability and Partition Tolerance) side this means that you don't full consistency. Redis is persistent BUT the persistent store really sucks. The right fit for Redis usage will be in the case that your design fits very well on the key store structure and you deal with data in memory and you don't rely on Redis persistence model, in other words you have the data persistent in other datastore more Consistency them Redis.

Twitter uses Redis as a Cache, this also a good usage of him, since Redis have pre-optimized operations to work with sets operations you can have great advantage of that and this make Redis suck a unique tool on NOSQL Ecosystem.

Getting Redis

Redis is a awesome kick ass Kick Store NOSQL Database. If you don't have Linux you still can get fun.
Servicestack did a great job pre-compiling Redis for windows, so this will avoid some pain for you.

CODE :-)

Is a framework for Java developers deal with NOSQL engines in Java. Spring Data provides a smooth integration with spring core capabilities like AOP, Beans IoC and Redis trough JRedis.

You want use JRedis it self alone because its really easy, the a look in this sample code below:
package com.blogspot.diegopacheco.nosql.redis.jredis.test;

import org.jredis.JRedis;
import org.jredis.ri.alphazero.JRedisClient;
import static org.jredis.ri.alphazero.support.DefaultCodec.*;

public class JRedisTest {
 public static void main(String[] args) throws Throwable {
  
  JRedis jredis = new JRedisClient("localhost", 6379, "jredis", 0);
  jredis.ping();  
  jredis.set("diegoPachecoJRedisKey", "Pacheco Value JRedis");
  System.out.println( toStr( jredis.get("diegoPachecoJRedisKey") ) );
  
 }
}
You can get full sample in my SVN repository here.

Here you can see another sample working with Redis API for Ruby. (You must do: $ gem install redis). You also need run the redis server before redis-server.exe (Code in my github repository)
require 'rubygems'
require 'redis'

r = Redis.new
r.set "diegopacheco_1", "first tweet"
puts r.get "diegopacheco_1"

Simple and easy :D In order to take real advantage of Redis you must use it, have said that you must start think flat, this cloud be tricky depending how much your familiar with Relational databases, sometimes is really a thinking and modeling exercise.

Cheers,

Popular posts from this blog

Kafka Streams with Java 15

Rust and Java Interoperability

HMAC in Java