Giter Club home page Giter Club logo

banana-redis's Introduction

Build Status

WARNING - THIS MODULE IS IN A VERY EARLY STAGE!

I am actively working on it, big changes may happen at any time (and any contribution is welcome!)

banana-redis

This banana (that is, a Bananarama module) contains a simple adapter for redis.io This module does not want to be an ORM; at now, is more something to keep order in the redis keyspace.

Usage

Objects are serialized/deserialized using redis HashSets. Each object is serialized as a value at a key generated by a getter method annotated with org.bananarama.crud.redis.annotations.KeyGenerator; during the deserialization, the key is passed to a setter method to parse the gei and save in a local property the unique identifier for the instance,.

CRUD operations are supported, with some limitations (eg: Read.all() and Read.where() are not supported)

First of all, extend the abstract class org.bananarama.crud.redis.RedisAdapter; the method protected abstract Jedis getJedis(); must be implemented to provide a valid jedis connection.

This is a simple class that can be serialized/desderialized using his banana:

package org.bananarama.redis.entities;

import org.bananarama.annotation.Banana;
import org.bananarama.crud.redis.RedisAdapterImpl;
import org.bananarama.crud.redis.annotations.KeyGenerator;

@Banana(adapter = RedisAdapterImpl.class)
public class Host {
    
    // This field contains the id of the instance. No need to annotat ethis field,
    // in Redis we create the key using other methods
    private String hostname;
            
    private String commonProperty;

    public Host() {
    }

    public Host(String hostname) {
        this.hostname = hostname;
    }

    public String getCommonProperty() {
        return commonProperty;
    }

    public void setCommonProperty(String commonProperty) {
        this.commonProperty = commonProperty;
    }

    // This annotation identify the method to use to convert the instance id to 
    // the string to use as key in redis
    @KeyGenerator
    public String getHostnameKey() {
        return "host:" + hostname;
    }
    
    // We have to annotate both the setter and the getter. 
    @KeyGenerator
    public void setHostnameKey(String key) {
        this.hostname = key.split(":")[1];            
    }

    public String getHostname() {
        return hostname;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
    }
    
    
    
}

Inheritance is implemented, see the tests.

METTI UN TEST PER CRUD con bananarama, hai messo solo com'e è annotata la classe! banana.read(GoogleHost.class).fromKeys <-- questo è l'id di host, viene poi tradotto in una chiave dall'adapter

Current limitations

  • Fields are ignored, only public properties are serialized/deserialized
  • An object can have only simple types (no list or objects as properties)
  • Only direct inheritance is supported
  • Instances must be "pojo"s

Roadmap

  • Le classi devono avere setter/getter ed un costruttore vuoto
  • Mappa solo getter/setter, ignora i fields
  • I setter ed i getter devono essere oggetti, non primitive (Double non double)

banana-redis's People

Contributors

totomz avatar

Watchers

James Cloos avatar  avatar

banana-redis's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.