Monday 15 December 2014

Thread safe Jedis client

Jedis is neat client library for Redis. The redis java client (Jedis) object provided by the library is not thread safe. Hence, if an application was muli-threaded, it should ideally be using a JedisPool object (which is thread-safe) or it would be facing a lot of unpredictable behavior and weird exceptions. JedisPool is a Jedis clients pool implementation using the Apache commons pool 2 API.

However, managing a pool and its resources might bring in some complexity and length to the app's implementation. So, I thought abstracting this resource management might help out the developer a lot. I've hosted the implementation on github. A new ThreadSafeJedis class has been introduced which will internally manage pooled jedis objects, and provide an interface similar to that of a Jedis class, but will be awesomely thread safe!

Background: The Jedis class currently uses a single Client object in all it's methods, which reasons the "thread unsafe" nature. Hence, the class cannot be simply extended. All the commands (which are methods) use the client object to launch commands. To introduce thread safe nature, each command must be launched using a client which has been freshly fetched from a pool, which means that all the  methods need to re-implemented in a fashion that they would:
  • borrow a client, 
  • launch the operation, 
  • record response,
  • return the client back to the pool 
  • and return the response back to the callee. 
And that's it!

11 comments:

  1. Hi Nachi,

    This sounds very useful - please lmk (@itamarhaber or itamar at redislabs dot com) once you've finalized the implementation so I can promote it in my newsletter :)

    Cheers!

    ReplyDelete
  2. Hi Itamar,

    Sounds great! Will definitely do. :)

    ReplyDelete
  3. Hi Nachi
    Great news for me. Thank you so much

    ReplyDelete
  4. Hi Nachi,

    I have cluster ( 2 nodes) of application servers. Each application is sharing redis cache also each node independently updates the cache. How do I ensure synchronization across node to make sure no cache gets overriden. I ma using Jedis client

    ReplyDelete
  5. Metallic Thread: This kind of thread has a center wrapped with a metal thwart which might be covered with silver amalgam, and shading is added to this thwart with a polyester film which may likewise be connected as an undercoating. Metallic thread is a standout amongst the most tough accessible available.best place to buy machine embroidery thread

    ReplyDelete
  6. I have cluster ( 2 nodes) of application servers. Each application is sharing redis cache also each node independently updates the cache. How do I ensure synchronization across node to make sure no cache gets overriden. I ma using Jedis client
    pinoy1tv

    ReplyDelete
  7. LEDs are easier to maintain. LEDs can be left fasadskylt belysning alone and a quick wipe over once in a while is all they need.
    LEDs are solid state. There is no filament or glass to break and they are robust even in wet conditions. They can even be used underwater in some circumstances.

    ReplyDelete
  8. The popularity of magic shops also grew and in 1982, Chew Kin Song opened a Magic & Novelty Corner at the Chinese Book Section of Popular Book Co Pte Ltd on the 4th Floor of Bras Basah Complex. Gician Rooftop for rent in Singapore Tan also opened up his first magic shop at Parkway Parade which subsequently moved to Marina Square and was managed by Richard Ang. Besides this main shop, he distributed magic items and sets through department stores.

    ReplyDelete
  9. DECORATIVE ART LIGHTING- Use of LED for decorative ljusskyltar led purpose is a traditional practice. People use various LED items to adorn their Christmas trees, frames, showcase and range of LED products to produce festive light.

    ReplyDelete
  10. Are you waiting for the DVD release or the 123 movies television premiere of a new Hollywood film in your country or state? The medium of the internet can instantly get you the movie you are eagerly waiting for, through completely free movie downloads provided by various websites.

    ReplyDelete
  11. Well, Globex Documents provides all the solutions to the worries regarding your passports. If you have any kind of problem or any issue regarding the real or fake passport, you can buy fake passport
    just contact Globex Documents and let us know what kind of service you require. You will be provided with all those services as soon as possible.

    ReplyDelete