<p>Hello. I try to do my own dispatcher with redis db. I have problem with disconnecting module wrom redis. Redis server is remote microsoft public server. This good solution for many companies and it works stable<br>
THe FIrst Isuue I saw when used</p>

<p>modparam("ndb_redis", "server", "name=srv1;addr=non_local_serv;port=6379;db=4;pass=mypass")</p>

<p>[TOASTERISK]<br>
redis_cmd("srv1", "EXISTS $si", "s");<br>
    xlog("L_INFO","ASTERISK with ip $si is {$redis(s=>value)}");</p>

<pre><code>$var(setid)=0;
if ($redis(s=>value) == 0) {    
      xlog("L_INFO","Request {$rm} from $si != {$var(dest)} It means call NOT from ASTRISK");
    }
</code></pre>

<p>And when this call begins I get  s value. But If I EXISTS it from redis comsole there is successfull reply.</p>

<p>Sometimes I see this at kamailio log</p>

<p>redisc_exec(): Redis error: Server closed the connection</p>

<p>I tried MONITOR redis from cli, but nothing happends when disconnect. (nothing means -nothing at the cli)</p>

<p>So I tried one more thing:<br>
I have some pools of requests<br>
1. When options recieved to kam from asterisk</p>

<p>if (is_method("OPTIONS"))<br>
        {<br>
            if ($sp == 50600) {</p>

<pre><code>            redis_cmd("srv1", "AUTH mylonglongpass"","r")
            redis_cmd("srv1", "SET $si $TS", "r");
            redis_cmd("srv1", "EXPIRE $si 20", "r");

        }
</code></pre>

<p>}</p>

<p>It works fine (Intresting that this works fine with the PASS through modparam key too)</p>

<p>Second pool when KAmailio choose ASTERISK to send INVITE from redis </p>

<pre><code>    #DISPATCHER_NEW 
            #$setid - is another var that gets from sql db.
    $var(priority)=1;
    redis_cmd("srv1", "AUTH mylonglongpass", "p");

           while ($redis(b=>value) == 0)
    {
    xlog("L_INFO","{$rm} priority now is $var(priority) and setid $var(setid)\n");
    redis_cmd("srv1", "EXISTS $var(setid):$var(priority)", "e");
    xlog("L_INFO","ASTERISK with customer $var(setid) and priority $var(priority) id {$redis(e=>value)} (if 1 - exists, 0 - not exisits)");
</code></pre>

<h2>Regis correctly get reply always</h2>

<pre><code>    if ($redis(e=>value) == 1)
    {
        redis_cmd("srv1", "GET $var(setid):$var(priority)", "a"); 

               #get IP of asterisk. Always get right value too

xlog("L_INFO","ASTERISK with customer $var(setid) and priority $var(priority)  is {$redis(a=>value)} (if 0 - not exisits)");
        redis_cmd("srv1", "GET $redis(a=>value)", "b"); #check timestamp that set at redis OPTION request
</code></pre>

<h2>There are I have truble when use AUTH command because redis return  after GET. If i do GET from cli - all ok.</h2>

<pre><code>        xlog("L_INFO","ASTERISK with customer $var(setid) and priority $var(priority) have timestamp {$redis(b=>value)} (if null - no timestamp. This means it down. Get new asterisk)");

        if ($redis(b=>value) == 1){

            $du="sip:"+$redis(a=>value)+":50600";
        }
        else{
            $var(priority)=$var(priority)+1;
            }
    }
</code></pre>

<p>Offcource I checked all parameteres - database name and another connection attrs of modparam</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/kamailio/kamailio/issues/108">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36Zbw04tUn7bfToUvgPPb9Jz-BGTM9ks5nzX4NgaJpZM4Drlx-.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://github.com/kamailio/kamailio/issues/108"></link>
    <meta itemprop="name" content="View Issue"></meta>
  </div>
  <meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>