https://github.com/scalajs-io/redis
This is a complete and feature rich Redis client for node.js. It supports all Redis commands and focuses on high performance.
https://github.com/scalajs-io/redis
Last synced: 4 months ago
JSON representation
This is a complete and feature rich Redis client for node.js. It supports all Redis commands and focuses on high performance.
- Host: GitHub
- URL: https://github.com/scalajs-io/redis
- Owner: scalajs-io
- Created: 2017-04-06T21:02:01.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T23:11:08.000Z (about 6 years ago)
- Last Synced: 2025-01-17T22:42:24.985Z (5 months ago)
- Language: Scala
- Size: 19.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Redis API for Scala.js
================================
[redis](http://redis.github.io/node-redis-native/2.2/api/) - 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.* [SBT v1.2.x](http://www.scala-sbt.org/download.html)
### Build/publish the SDK locally```bash
$ sbt clean publish-local
```### Running the tests
Before running the tests the first time, you must ensure the npm packages are installed:
```bash
$ npm install
```Then you can run the tests:
```bash
$ sbt test
```### Examples
##### Reading and writing hashes
```scala
import io.scalajs.JSON
import io.scalajs.nodejs._
import io.scalajs.npm.redis._
import io.scalajs.util.ScalaJsHelper._
import scalajs.jsval 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
```scala
import io.scalajs.nodejs._
import io.scalajs.npm.redis._val sub = Redis.createClient()
val pub = Redis.createClient()
var msg_count = 0sub.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
```scala
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:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "redis" % "0.5.0"
```Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```