Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since I haven't got any good answers, I came up with this solution (BTW thanks @Simon and @Alex for your answers!).</p> <p>I want to share it with all of the community as a reference. Of course, any corrections will be highly appreciated.</p> <pre><code>using System; using System.Net.Sockets; using BookSleeve; namespace Redis { public sealed class RedisConnectionGateway { private const string RedisConnectionFailed = "Redis connection failed."; private RedisConnection _connection; private static volatile RedisConnectionGateway _instance; private static object syncLock = new object(); private static object syncConnectionLock = new object(); public static RedisConnectionGateway Current { get { if (_instance == null) { lock (syncLock) { if (_instance == null) { _instance = new RedisConnectionGateway(); } } } return _instance; } } private RedisConnectionGateway() { _connection = getNewConnection(); } private static RedisConnection getNewConnection() { return new RedisConnection("127.0.0.1" /* change with config value of course */, syncTimeout: 5000, ioTimeout: 5000); } public RedisConnection GetConnection() { lock (syncConnectionLock) { if (_connection == null) _connection = getNewConnection(); if (_connection.State == RedisConnectionBase.ConnectionState.Opening) return _connection; if (_connection.State == RedisConnectionBase.ConnectionState.Closing || _connection.State == RedisConnectionBase.ConnectionState.Closed) { try { _connection = getNewConnection(); } catch (Exception ex) { throw new Exception(RedisConnectionFailed, ex); } } if (_connection.State == RedisConnectionBase.ConnectionState.Shiny) { try { var openAsync = _connection.Open(); _connection.Wait(openAsync); } catch (SocketException ex) { throw new Exception(RedisConnectionFailed, ex); } } return _connection; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload