/redis

This is a complete and feature rich Redis client for node.js. It supports all Redis commands and focuses on high performance.

Primary LanguageScala

Redis API for Scala.js

redis - This is a complete and feature rich Redis client for node.js.

Description

This is a complete and feature rich Redis client for node.js. It supports all Redis commands and focuses on high performance.

Build Requirements

Build/publish the SDK locally

 $ sbt clean publish-local

Running the tests

Before running the tests the first time, you must ensure the npm packages are installed:

$ npm install

Then you can run the tests:

$ sbt test

Examples

Reading and writing hashes
import io.scalajs.JSON
import io.scalajs.nodejs._
import io.scalajs.npm.redis._
import io.scalajs.util.ScalaJsHelper._
import scalajs.js

val client = Redis.createClient(new RedisClientOptions())
client.hmset("hosts", "mjr", "1", "another", "23", "home", "1234")
client.hgetall("hosts", (err, obj) => {
assert(!isDefined(err))
  console.log(JSON.stringify(obj)) // { mjr: '1', another: '23', home: '1234' }
})
Publish and Subscribe
import io.scalajs.nodejs._
import io.scalajs.npm.redis._

val sub = Redis.createClient()
val pub = Redis.createClient()
var msg_count = 0

sub.onSubscribe((channel, count) => {
    pub.publish("a nice channel", "I am sending a message.")
    pub.publish("a nice channel", "I am sending a second message.")
    pub.publish("a nice channel", "I am sending my last message.")
})

sub.onMessage((channel, message) => {
    console.log("sub channel " + channel + ": " + message)
    msg_count += 1
    if (msg_count == 3) {
      sub.unsubscribe()
      sub.quit()
      pub.quit()
    }
})

sub.subscribe("a nice channel")
Monitoring
import io.scalajs.nodejs._
import io.scalajs.npm.redis._

val client = Redis.createClient()
client.monitor((err, res) => {
    console.log("Entering monitoring mode.")
})
client.set("foo", "bar")

client.onMonitor((time, args, raw_reply) => {
    console.log(time + ": " + args) // 1458910076.446514:['set', 'foo', 'bar'] 
})

Artifacts and Resolvers

To add the Redis binding to your project, add the following to your build.sbt:

libraryDependencies += "io.scalajs.npm" %%% "redis" % "0.5.0"

Optionally, you may add the Sonatype Repository resolver:

resolvers += Resolver.sonatypeRepo("releases")