Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to add TTL on keys into Redis #14

Open
Mickaelh51 opened this issue Jun 11, 2019 · 5 comments
Open

Possible to add TTL on keys into Redis #14

Mickaelh51 opened this issue Jun 11, 2019 · 5 comments

Comments

@Mickaelh51
Copy link
Contributor

Hi,
I use your dev with freeswitch mode.
I want to add TTL to delete redis keys or delete it when I receive BYE.
But add TTL is simplest than delete key with BYE no ?

I'm not sure, but I think the redis data is used before the SIPREC 200OK generation. After that, I can delete key into redis....

thanks in advance

@Mickaelh51 Mickaelh51 changed the title Possible to add TTL with Redis Possible to add TTL on keys into Redis Jun 11, 2019
@davehorton
Copy link
Collaborator

yes, I agree that we should use a TTS to expire redis keys, but that is in fact what I am doing here:

https://github.com/davehorton/drachtio-siprec-recording-server/blob/95a6e710d71d5eba373155821effea7921649f1f/lib/freeswitch-call-handler.js#L111

I set a 10 second expires value.

Are you seeing keys not getting cleared from redis?

@Mickaelh51
Copy link
Contributor Author

I knew it ;) but no, all keys stay in redis... I don't understand why...
Do you have an idea please ?
thanks in advance

@davehorton
Copy link
Collaborator

What version of redis server are you running? Per this:

https://redis.io/commands/set

it seems like that option was added in Redis 2.6.12.

you could always try changing the code to do it this way:

client.multi(()
   .set(opts.sessionId, opts.sdp2)
   .expire(opts.sessionId, 10)
   .exec((err, replies) => ..

@Mickaelh51
Copy link
Contributor Author

Mickaelh51 commented Jun 14, 2019

Hi,
I use this redis version (not in docker), installed from debian package:

Redis server v=3.2.6 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=c9ca860b301a190d

I tested but I have the same issue :(

the code:

function storeUnusedSdp(opts) {
  return new Promise((resolve) => {
    console.log(`sessionId: ${opts.xcid} / sdp: ${opts.sdp2}`);
    client.multi()
      .set(opts.xcid, opts.sdp2)
      .expire(opts.xcid, 10)
      .exec((err, replies) => {
        if (err) throw err;
        resolve(opts) ;
    }) ;
  });
}

I can see my key but the TTL is -1

127.0.0.1:6379> TTL 201-1560495744.2171985
(integer) -1

I can force a TTL with cli and it woks:

127.0.0.1:6379> EXPIRE 201-1560495744.2171985 10
(integer) 1
127.0.0.1:6379> TTL 201-1560495744.2171985
(integer) 7

After that I downloaded and compiled the last redis server (http://redis-5.0.5.tar.gz/)
No changes :(
I found this: redis/node-redis#1000

Other test:

I tested with:

client.setex(opts.xcid, 10, opts.sdp2);

same issue.

But I created other simple script with the same data, and setex works like a charm...

I'm sorry but I don't know what to try.. :(

@Mickaelh51
Copy link
Contributor Author

After lot of things, I found.
The first 'set' into storeUnusedSdp is set with TTL, but the code rewrite this data into (handleLeg2SiprecInvite -> exchangeSdp) without TTL...
So all registers can't be deleted ... I add TTL in exchangeSdp and it works like a charm (but I use setex) ;)

function storeUnusedSdp(opts) {
  console.log(opts)
  return new Promise((resolve) => {
    if (!opts.xcid) { 
      console.log(`No xcid`);
      return opts.res.send(500, {
        headers: {
          'X-Reason': 'No X-cid header'
        }
      }
        );
    }
    console.log(`sessionId: ${opts.xcid} / sdp: ${opts.sdp2}`);
    client.setex(opts.xcid, 10, opts.sdp2, (err, reply) => {
      if (err) throw err;
      resolve(opts) ;
    }) ;
  });
}
-------------
function exchangeSdp(sessionId, sdp) {
  return new Promise((resolve, reject) => {
    client.multi()
      .get(sessionId)
      .setex(sessionId, 10, sdp)
      .exec((err, replies) => {
        if (err) return reject(err);
        resolve(replies[0]);
      });
  });
}
 ```

But I don't understand why you add TTL in the first set (to store unused sdp), and there is no TTL when you use it with the leg2 (in exchangeSdp)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants