Skip to content

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

Notifications You must be signed in to change notification settings

scalajs-io/redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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") 

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages