簡體   English   中英

如何檢查Redis中是否已存在會話ID

[英]How do I check if a session id already exists in redis

我有以下代碼,但我不確定如何檢查會話密鑰是否已存在,因為我不想創建另一個Redis會話(如果已存在)。

這個請求對象是每次調用都是新的,但是我知道event.sender.id在每個請求上都是相同的。

     // If not set then create the session object
     if (!req.session.key) {
       console.log('Set session variable');
       req.session.key = event.sender.id;
       console.log('*** SESSION CREATED WITH ' + event.sender.id);
     }

Server.js

const redis = require("redis");
const client = redis.createClient(); 
const hostname = '127.0.0.1'; 
const port = 6379;


client.on("error", function (err) {
    console.log("Error " + err); });

var session_id_key = event.sender.id ; //your id

client.exists("key",session_id_key, function (err, replies) {

    if(!err && replies===1){

        console.log("THE SESSION ID ALREADY PRESENT ");
    }else{
        console.log("THE SESSION ID DOES NOT PRESENT");
    } });

答案是:會議ID已經存在

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM