Code Monkey home page Code Monkey logo

akre's Introduction

Akre

Akre is a Scala Redis client implemented using Akka, with command pipelining and convenient Actor and Future APIs.

Status

Build Status

Consider this beta software. Akre is being used in production, but currently only a handful of commands have strongly-typed representations, and the interface is subject to change.

Getting Started

Include the following line in your build.sbt to get started:

libraryDependencies += "org.programmiersportgruppe.akre" %% "akre-client" % "0.19.1"

The easiest way to use Akre is through the AkreClient Future-based API described below. If you're interested in using Akre from other Akka actors, you can either directly use RedisConnectionActor, or use it through a Resilient Pool like AkreClient does.

Using the AkreClient API and Futures

Futures offer an elegant way of dealing with asynchronous requests, and the future API is arguably the easiest way to use Akre.

First we create a client:

val client = new RedisClient(
    actorRefFactory     = actorSystem,
    serverAddress       = InetSocketAddress.createUnresolved("127.0.0.1", 6379),
    connectTimeout      = Timeout(1000, MILLISECONDS),
    requestTimeout      = Timeout(1000, MILLISECONDS),
    numberOfConnections = 1
)

Then we wait for the client to be ready:

client.waitUntilConnected(5.seconds)

Now we can send commands using the execute method:

val response: Future[RSuccessValue] = client.execute(SET(Key("hello"), "cruel world"))

println(Await.result(response, 5.seconds))

We can also call execute methods on the commands themselves, which help guide us to more specific, command-appropriate return types:

val value: Future[Option[ByteString]] = GET(Key("hello")).executeByteString(client)

val utf8Decoded: Future[Option[String]] = GET(Key("hello")).executeString(client)

When you're done with client, don't forget to shut down the actor system if you're not using it for something else:

actorSystem.shutdown()

Akre Development

Pull requests are welcome.

You should run

sbt +test +doc

prior to pushing to validate your changes.

The release process is documented in RELEASING.md.

Why?

A teammate of mine implemented a caching solution for our system, which is written in Scala. He was not satified with existing Scala clients for Redis, and ended up using Jedis. We then encountered stability problems on MacOS X with versions 7 and 8 of the JDK. A client based on Akka seamed like a reasonable thing to do. At some point, I'll look at the other Scala clients. Maybe I will abandon this client in favour of something more established, but at least this will have been a good learning experience for me.

akre's People

Contributors

barnardb avatar fleipold avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

akre's Issues

Create `RedisClient` without configuration

Currently something like the following is necessary to use a RedisClient:

val actorSystem = ActorSystem("akre-example", ConfigFactory.parseString(
  """
  akka {
    actor.deployment {
      /akre-redis-pool {
        dispatcher = akre-coordinator-dispatcher
      }
    }
  }
  akre-coordinator-dispatcher {
    mailbox-type = org.programmiersportgruppe.redis.client.ResilientPoolMailbox
  }
  """))

This is inconvenient, and breaks the actorlessness of the RedisClient interface. The mailbox should get wired up on its own, and possibly also the dispatcher type.

RedisClient execution can hang for requestTimeout when selected connection actor dies

There is a RedisClientAcceptanceTest case that checks that the RedisClient will "recover from the server going down nicely". It does this by sending a SHUTDOWN command to the server, then restarting the server, and immediately sending a SET command. The test can randomly fail with a 3-second AskTimeoutException when the SET command is sent before the ResilientPool gets the Terminated message informing it that the connection actor has died. The pool sends the command to the connection actor, but that actor dies before it processes the message. So the message becomes a dead letter and disappears into the ether, the pool receives the Terminated message and creates a new RedisConnectionActor, and the ask construct in RedisClient.execute eventually times out.

Since the actor system as a whole actually has the information that the SET command hasn't been sent to the server, it would be very nice if we could either resend it or at least fail quickly.

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.