Scredis 介绍
Scredis 是一个 Redis 的 Scala 客户端开发包。基于
Akka 构建,特点是 Reactive、非堵塞以及超级快。
示例代码:
import scredis._ import scala.util.{ Success, Failure } // Creates a Redis instance with default configuration. // See reference.conf for the complete list of configurable parameters. val redis = Redis() // Import internal ActorSystem's dispatcher (execution context) to register callbacks import redis.dispatcher // Executing a non-blocking command and registering callbacks on the returned Future redis.hGetAll("my-hash") onComplete { case Success(content) => println(content) case Failure(e) => e.printstacktrace() } // Executes a blocking command using the internal, lazily initialized BlockingClient redis.blocking.blPop(0, "queue") // Subscribes to a Pub/Sub channel using the internal, lazily initialized SubscriberClient redis.subscriber.subscribe("My Channel") { case message @ PubSubMessage.Message(channel, messageBytes) => println( message.readAs[String]() ) case PubSubMessage.Subscribe(channel, subscribedChannelsCount) => println( s"Successfully subscribed to $channel" ) } // Shutdown all initialized internal clients along with the ActorSystem redis.quit()
Scredis 官网
https://github.com/Livestream/scredis
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。