How does nodejs redis set the expiration time?

how does nodejs redis set the expiration time?

Mar.10,2021

call the expired command of redis.
EXPIRE key seconds
this has nothing to do with what language is used.


const redis = require("redis");
const redisConfig = {
    host: "redisip",
    port: ""
};
const __createClient = () => {
    const client = redis.createClient(redisConfig.port, redisConfig.host);
    //redis
    client.on("error", function (err) {
        logger("redis error: " + err);
    });
    return client;
};

const client = __createClient();
client.expire("key", "", (err, isSuccess) => {
    client.quit();
    if (err || !isSuccess) {
        //your code
    } else {
        //your another code
    }
});

const redis = require('redis')
import { redisConfig } from '../config/index';
const redisClient = redis.createClient(redisConfig);
redisClient.select(2, (res) => {
    console.log(res)
})
export function setItem(key, value, exprires) {
    redisClient.set(key, value);
    //
    if (exprires) {
        redisClient.expire(key, exprires);
    }
}

can refer to

used in my project.
Menu