Giter VIP home page Giter VIP logo

redissed's Introduction

. Redissed

Redis Kotlin wrapper inspired on Exposed

Getting started

Gradle

dependencies {
    compile("br.com.devsrsouza:redissed:1.1.0")
}

Maven

<dependency>
    <groupId>br.com.devsrsouza</groupId>
    <artifactId>redissed</artifactId>
    <version>1.1.0</version>
</dependency>

Sample

import br.com.devsrsouza.redissed.RedisObject

class MyObject(database: String, commands: RedissedCommands) : RedisObject(database, commands) {
  var hello: String? by string()
  var hi: String by string("Hi")

  val other: OtherObject by obj { OtherObject(it, commands) }
}

class OtherObject(database: String, commands: RedissedCommands) : RedisObject(database, commands) {
  var something = string()

  var points: Int = int(0)
}

val database = "my:db"
val commands: RedissedCommands = myClient.redissed

val my = MyObject("$database:obj", commands)

my.hello = "Hello" // setting "Hello" to my:db:obj:hello
my.hi // getting my:db:obj:hi from Redis if not exist return default "Hi"

my.hello = null // removing data from my:db:obj:hello

my.other.something = "Anything" // setting "Anything" to my:db:obj:other:something
my.other.points = 10 // setting 10 to my:db:obj:other:points

Supported Redis Clients

  • Jedis
  • Lettuce

Jedis

import br.com.devsrsouza.redissed.clients.redissed
import br.com.devsrsouza.redissed.RedissedCommands

val jedis = Jedis("localhost", 6379)
jedis.connect()

val commands: RedissedCommands = jedis.redissed

Lettuce

import br.com.devsrsouza.redissed.clients.redissed
import br.com.devsrsouza.redissed.RedissedCommands

val redis = RedisClient.create(RedisURI.create("localhost", 6379))
val conn = redis.connect()
val sync = conn.sync()

val commands: RedissedCommands = sync.redissed

Supported types

string(): String?
string(default: String): String
byte(): Byte?
byte(default: Byte): Byte
short(): Short?
short(default: Short): Short
int(): Int?
int(default: Int): Int
long(): Long?
long(default: Long): Long
boolean(): Boolean?
boolean(default: Boolean): Boolean
obj(factory: (key: String) -> RedisObject): RedisObject

Expire

Auto expires a key

var your_key: String? by string().expire(5) // in seconds

You can use withExpire to tell the expiration time for a specific value or get the expiration time of a value

var my_key: Pair<String, Int> by string("my default key").withExpire()

my_key = "my new value expiring in 10 sec" to 10

// get the expiration time of a key
val (value, time) = my_key
// returns the expiration time in seconds or
// returns -2 if the key does not exist.
// returns -1 if the key exists but has no associated expire. 

redissed's People

Contributors

devsrsouza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

redissed's Issues

`jedis.redissed` extension getter cannot be resolved

In Kotlin 1.4.10, the IDE cannot resolve jedis.redissed getter, even if I implicitly add the import.

I simply added the dependencies (Redissed and Jedis) and copied the code from the READ ME file in this repository

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import br.com.devsrsouza.redissed.RedisObject
import br.com.devsrsouza.redissed.RedissedCommands
import redis.clients.jedis.Jedis

class MainActivity : AppCompatActivity(R.layout.activity_main) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val jedis = Jedis("localhost", 6379)
        jedis.connect()

        val commands = jedis.redissed

        val my = MyObject("my:db:obj", commands)

        my.hello = "Hello" // setting "Hello" to my:db:obj:hello
        my.hi // getting my:db:obj:hi from Redis if not exist return default "Hi"

        my.hello = null // removing data from my:db:obj:hello

        my.other.something = "Anything" // setting "Anything" to my:db:obj:other:something
        my.other.points = 10 // setting 10 to my:db:obj:other:points
    }

    class MyObject(database: String, commands: RedissedCommands) : RedisObject(database, commands) {
        var hello: String? by string()
        var hi: String by string("Hi")

        val other: OtherObject by obj { OtherObject(it, commands) }
    }

    class OtherObject(database: String, commands: RedissedCommands) : RedisObject(database, commands) {
        var something by string()

        var points by int(0)
    }
}

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.