Code Monkey home page Code Monkey logo

nedis's Introduction

nedis

An event-driven, asynchronous redis client based on netty

How to use

Add this to your pom.xml. We deploy nedis to https://oss.sonatype.org.

<dependency>
  <groupId>com.wandoulabs.nedis</groupId>
  <artifactId>nedis-client</artifactId>
  <version>0.1.1</version>
</dependency>

To use it

NedisClientPool nedisPool = NedisClientPoolBuilder.create().timeoutMs(5000)
        .remoteAddress("rediserver", 6379).build();
NedisClient nedis = NedisUtils.newPooledClient(nedisPool);
nedis.set(NedisUtils.toBytes("foo"), NedisUtils.toBytes("bar")).sync();
byte[] value = nedis.get(NedisUtils.toBytes("foo")).sync().getNow();
System.out.println(NedisUtils.bytesToString(value));
nedis.close().sync();

Java7 is required to build or use nedis.

For codis users

Add this to your pom.xml.

<dependency>
  <groupId>com.wandoulabs.nedis</groupId>
  <artifactId>codis-client</artifactId>
  <version>0.1.1</version>
</dependency>

To use it

RoundRobinNedisClientPool nedisPool = RoundRobinNedisClientPool.builder()
        .poolBuilder(NedisClientPoolBuilder.create().timeoutMs(5000)).curatorClient("zkserver:2181", 30000)
        .zkProxyDir("/zk/codis/db_xxx/proxy").build().sync().getNow();
NedisClient nedis = NedisUtils.newPooledClient(nedisPool);
nedis.set(NedisUtils.toBytes("foo"), NedisUtils.toBytes("bar")).sync();
byte[] value = nedis.get(NedisUtils.toBytes("foo")).sync().getNow();
System.out.println(NedisUtils.bytesToString(value));
nedis.close().sync();

Performance

Nedis is NOT faster than jedis, especially if you use it in a synchronized way. In nedis, the requests on the same connection will be pipelined automatically if possible, but it is still NOT faster than jedis if you explicitly use a pipeline when using jedis.

So please use nedis with caution.

If you are an expert of netty, you could try to use EpollEventLoopGroup and add -Dio.netty.allocator.type=pooled(default is unpooled in netty 4.0) when starting to increase performance.

nedis's People

Contributors

apache9 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.