redis-algebra-interpreter


License

License

MIT
Categories

Categories

Redis Data Databases
GroupId

GroupId

com.github.ethul
ArtifactId

ArtifactId

redis-algebra-interpreter_2.10
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

redis-algebra-interpreter
redis-algebra-interpreter
Project URL

Project URL

https://github.com/ethul/redis-algebra-interpreter
Project Organization

Project Organization

com.github.ethul
Source Code Management

Source Code Management

https://github.com/ethul/redis-algebra-interpreter

Download redis-algebra-interpreter_2.10

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.ethul/redis-algebra-interpreter_2.10/ -->
<dependency>
    <groupId>com.github.ethul</groupId>
    <artifactId>redis-algebra-interpreter_2.10</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.ethul/redis-algebra-interpreter_2.10/
implementation 'com.github.ethul:redis-algebra-interpreter_2.10:0.1.0'
// https://jarcasting.com/artifacts/com.github.ethul/redis-algebra-interpreter_2.10/
implementation ("com.github.ethul:redis-algebra-interpreter_2.10:0.1.0")
'com.github.ethul:redis-algebra-interpreter_2.10:jar:0.1.0'
<dependency org="com.github.ethul" name="redis-algebra-interpreter_2.10" rev="0.1.0">
  <artifact name="redis-algebra-interpreter_2.10" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.ethul', module='redis-algebra-interpreter_2.10', version='0.1.0')
)
libraryDependencies += "com.github.ethul" % "redis-algebra-interpreter_2.10" % "0.1.0"
[com.github.ethul/redis-algebra-interpreter_2.10 "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.10.4
com.github.ethul : redis-algebra_2.10 jar 0.1.1
net.debasishg : redisreact_2.10 jar 0.5

test (2)

Group / Artifact Type Version
org.specs2 : specs2_2.10 jar 2.2.2-scalaz-7.1.0-M3
org.scalacheck : scalacheck_2.10 jar 1.10.1

Project Modules

There are no modules declared in this project.

Redis Algebra Interpreter

An interpreter for running programs written using the Redis Algebra. The interpreter uses the non-blocking Redis client Scala Redis NB under the hood for performing the commands of the algebra.

Install

Releases and snapshots of the Redis Algebra Interpreter are published to the Sonatype OSS Repository Hosting Service. The necessary SBT Resolvers may be added as follows to your SBT build file.

resolvers += "Sonatype releases" at "http://oss.sonatype.org/content/repositories/releases/"

resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"

Usage

import com.redis.RedisClient

import akka.actor.ActorSystem
import akka.util.Timeout

import scala.concurrent.duration.Duration

import scalaz.{CharSet, NonEmptyList}, NonEmptyList.nels
import scalaz.std.list._
import scalaz.syntax.{Ops, comonad, monad, traverse}, comonad._, monad._, traverse._
import scalaz.syntax.std.list._

import redis.algebra.{R, all}, all._
import redis.algebra.interpreter.nonblocking.{NonBlocking, future}, future._

val e0 =
  set[R]("key".utf8, "value".utf8) >>
  get[R]("key".utf8)

val e1 =
  set[R]("counter".utf8, "100".utf8) >>
  incr[R]("counter".utf8) >>
  incr[R]("counter".utf8) >>
  incrby[R]("counter".utf8, 10)

val e2 =
  List("first".utf8, "second".utf8, "third".utf8).map(a => rpush[R]("messages".utf8, nels(a))).sequenceU >>
  lrange[R]("messages".utf8, 0, 2)

implicit val duration = Duration(2, "seconds")

implicit val system = ActorSystem("redis-algebra-interpreter")

implicit val executionContext = system.dispatcher

implicit val timeout = Timeout(duration)

lazy val client = RedisClient("localhost", 6379)

implicit def StringToStringOps(a: String): StringOps = new StringOps { val self = a }

sealed abstract class StringOps extends Ops[String] { final def utf8 = self.getBytes(CharSet.UTF8).toIndexedSeq }

val r0 = NonBlocking.run(e0, client).copoint

val r1 = NonBlocking.run(e1, client).copoint

val r2 = NonBlocking.run(e2, client).copoint

println(r0)
// Some(ByteString(118, 97, 108, 117, 101))

println(r1)
// 112

println(r2)
// Vector(ByteString(102, 105, 114, 115, 116), ByteString(115, 101, 99, 111, 110, 100), ByteString(116, 104, 105, 114, 100))

Versions

Version
0.1.0