Skip to content

RedisClient library used for RedisStore #62

Open

Description

@afrancis-caregility

I am trying to use the RedisStore for sessionId storage and I am not seeing any entry in RedisDB for this. So, I want to know which RedisClient is being used to insert key in RedisDB.
I use "ioredis": "^5.2.5" in my nodejs application. The admin UI is working correctly. I was expecting an entry in Redis but not seeing one. So, I want to understand this a little better.

Activity

  1. darrachequesne commented on Feb 16, 2023

    @darrachequesne
    Member

    Hi! We use redis@3:

    "redis": "^3.0.2",

    Not sure the ioredis package supports the syntax here:

    export class RedisStore extends Store {
    private options: RedisStoreOptions;
    constructor(readonly redisClient: any, options?: Partial<RedisStoreOptions>) {
    super();
    this.options = Object.assign(
    {
    prefix: "socket.io-admin",
    sessionDuration: 86400,
    },
    options
    );
    }
    private computeKey(sessionId: string) {
    return `${this.options.prefix}#${sessionId}`;
    }
    doesSessionExist(sessionId: string): Promise<boolean> {
    return new Promise((resolve, reject) => {
    this.redisClient.exists(
    this.computeKey(sessionId),
    (err: Error | null, result: any) => {
    if (err) {
    reject(err);
    } else {
    resolve(result === 1);
    }
    }
    );
    });
    }
    saveSession(sessionId: string) {
    const key = this.computeKey(sessionId);
    this.redisClient
    .multi()
    .set(key, true)
    .expire(key, this.options.sessionDuration)
    .exec();
    }
    }

    But you should be able to write your own store by extending the Store class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions