项目作者: wilhg

项目描述 :
An ORM for Redis, support conditional query.
高级语言: Kotlin
项目地址: git://github.com/wilhg/rendition.git
创建时间: 2017-01-07T07:10:25Z
项目社区:https://github.com/wilhg/rendition

开源协议:GNU Lesser General Public License v3.0

下载


Rendition

Rendition is an ORM for Redis, support conditional query.

Rendition = Redis + condition

Cause the Redis doesn’t support any index, it is hard to make conditional query. However it supports data structures such as Hash tables and Sorted set. Redition make use of these two data structures to implement index.

By using Redition, it will be possible to query conditionally in Redis.

How to Install

Usage

Model

You can use DSL way to define the model. Like this:

  1. object Book : Model("book", {
  2. it["id"] = int().primaryKey()
  3. it["author"] = string().index()
  4. it["publish"] = string().index()
  5. it["words"] = long().index()
  6. it["sales"] = long().index()
  7. it["introduce"] = string()
  8. it["date"] = string()
  9. })

You can also define the model withMap. Like this:

  1. val schema = mapOf(
  2. "id" to int().primaryKey(),
  3. "author" to string().index(),
  4. "publish" to string().index(),
  5. "words" to long().index(),
  6. "sales" to long().index(),
  7. "introduce" to string(),
  8. "date" to string()
  9. )
  10. object Book : Model("book", schema)

Find

  1. val book: Map<String, Any> = Book.find(0)
  1. val books1: Map<String, Any> = Book.findBy("author", "Me")
  2. val books2: Map<String, Any> = Book.findBy("id", 0)
  3. val books3: Map<String, Any> = Book.range("sales", 0, 1000)

Insert

  1. Book.insert {
  2. it["id"] = 0
  3. it["author"] = "Me"
  4. it["publish"] = "R.D"
  5. it["words"] = 100_000
  6. it["sales"] = 100_100_000
  7. }
  1. val data = mapOf(
  2. "id" to 0,
  3. "author" to "Me",
  4. "publish" to "R.D",
  5. "words" to 100_100,
  6. "sales" to 100_100_000,
  7. )
  8. Book.insert(data)
  1. val data0 = mapOf(
  2. "id" to 0,
  3. "author" to "Me",
  4. "publish" to "R.D",
  5. "words" to 100_100,
  6. "sales" to 100_100_000,
  7. )
  8. val data1 = mapOf(
  9. "id" to 1,
  10. "author" to "Me",
  11. "publish" to "R.D",
  12. "words" to 100_100,
  13. "sales" to 100_100_000,
  14. )
  15. Book.batchInsert(listOf(data0, data1))

Update

  1. Book.find(0).update {
  2. it["author"] = "Nobody"
  3. it["words"] = 200_000
  4. }
  5. Book.findBy("author", "Me").update {
  6. it["author"] = "Nobody"
  7. it["words"] = 200_000
  8. }

Delete

  1. Book.find(0).delete()
  2. Book.findBy("author", "Me").delete()

License

LGPL-3.0