Giter Site home page Giter Site logo

jedis-tool-kit's Introduction

Jedis Tool Kit

Jedis-tool-kit is a generic client for both single Redis database and cluster.

Jedis-lock

Jedis-lock is easy to use and simple implementation of distributed lock using Redis database and Jedis driver.

Because the master branch is no longer updated, this fork will add following features:

  • Use LUA scripts instead of SETNX for better atomicity
  • ReentrantLock support
  • JedisCluster support

How to use it?

To use it just:

String hosts = "ip:port, ip:port, ...";
JedisClientBuilder builder = new JedisClientBuilder(
        new JedisPoolConfig(), hosts, 5000, password, database, "client");
JedisGenericClient client = builder.getClient();
JedisLock lock = new JedisLock(client, "foobar");

then

lock.acquire();
try {
  // do some stuff
}
finally {
  lock.release();
}

That's it.

Into production

Please read Distributed lock with Redis before using it in production. Jedis-lock is good for single redis server and cluster without replica. Usually redis is very stable in most of the cases, it can run smoothly for months even years without a problem. But if you are going to use it in some serious conditions, like a heavily loaded master-slave redis cluster, it may have the problem of safety violation(Mutual exclusion. At any given moment, only one client can hold a lock). You should use Redisson which has implemented the Redlock algorithm.

Disclaimer

This 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.

License

The Apache Software License, Version 2.0

jedis-tool-kit's People

Contributors

miltonlai avatar bbossola avatar

Stargazers

 avatar Ivan Chernob avatar  avatar

Watchers

James Cloos avatar

Forkers

myxyz king1129

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.