1 Star 0 Fork 1

mefan / scala-redis-client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Scala Redis Client

Idiomatic Scala Redis client developed and used by Top10. This is a work-in-progress and, while it is used in production, should be treated as such.

Currently this client wraps the Java Jedis client and in places that still leaks out. We've had to patch Jedis in a few ways and have left the patched files in src/main/java. When the pull requests get merged in and released as a new Jedis version we'll get rid of them, but that doesn't look like it's going to happen any time soon.

Usage

  • Current 'stable' version: 1.16.0
  • Unstable version: 1.17.0-SNAPSHOT
  • Scala versions: 2.9.1, 2.9.2, 2.10.0

Published to the Sonatype release and snapshot repositories.

resolvers += "Sonatype OSS Releases" at "http://oss.sonatype.org/content/repositories/releases/"

libraryDependencies ++= Seq(
  "com.top10" %% "scala-redis-client" % "1.3.0" withSources()
)

Because we have had to bundle some patched files from Jedis, if you are using the assembly plugin you'll need to set a MergeStategy that chooses them:

mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
  {
    case PathList("redis", "clients", xs @ _*) => MergeStrategy.first
    case x => old(x)
  }
}

Please let us know if there's a better way of doing this.

You can instantiate SingleRedis and ShardedRedis using the Jedis config objects, but I guess you'd rather not. Optional arguments have (not particularly scientific) sensible defaults:

val redis = new SingleRedis("localhost", 6379, [Some("password")], [timeout], [poolSize])

val shards = Seq(Shard("localhost", 6379, [Some("password")], [timeout]),
                 Shard("localhost", 6380, [Some("password")], [timeout])
val shardedRedis = new ShardedRedis(shards, [poolSize], [hashing algorithm])

For the full API it's worth having a look through Redis.scala. If you find any operations that haven't been mapped from Jedis yet, just raise an issue (preferably, pull request).

It's all pretty straight-forward, using Seq and Option where appropriate. The pipelines are worth pointing out though. If you want to perform multiple operations that don't return any results, pass a PartialFunction to exec:

redis.exec(pipeline => {
  pipeline.set("some", "value")
  pipeline.sadd("set", "value")
})

If you want to get stuff, use the typed syncAndReturn function which returns a TupleN (up to 9) of the type that you expect:

val results = redis.syncAndReturn[Option[String], Map[String, Double], Seq[String], Set[String]](pipeline => {
  pipeline.get("somekey")
  pipeline.zrevrangeWithScores("sortedsetkey", 0, -1)
  pipeline.zrevrange("sortedsetkey", 0, -1)
  pipeline.smembers("setkey")
})

Unfortunately this only provides RUNTIME exceptions if you get the type parameters wrong (either the number or number of them). Will try an will out how to make this a compile time problem (pull requests welcome).

In a similar fashion, if you want to get a load of results of the same type, you can use syncAndReturnAllAs:

val results = redis.syncAndReturnAll[Map[String,Double]](pipeline => {
  (0 until 100).foreach(i => pipeline.zrevrangeWithScores("sortedsetkey:"+i, 0, -1))
})

Anyway, if you find any problems or ommissions, please let us know.

The MIT License (MIT) Copyright (c) 2013 Top10.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Idiomatic Scala Redis client developed and used by Top10. This is a work-in-progress and, while it is used in production, should be treated as such. 展开 收起
Scala
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Scala
1
https://gitee.com/mefaso/scala-redis-client.git
git@gitee.com:mefaso/scala-redis-client.git
mefaso
scala-redis-client
scala-redis-client
mine

搜索帮助