#Redis not saving in the db

17 messages · Page 1 of 1 (latest)

mossy dawn
#

maybe i dont understand the concept but when i save in the cache and then log to get the data i see it but when i go terminal and do GET ALL or GET 'key' its say nil

this is my microservice

main.ts

async function bootstrap() {
  const app = await NestFactory.createMicroservice<MicroserviceOptions>(
    ExpenseSummeryModule,
    { transport: Transport.REDIS, options: { host: 'localhost', port: 6379 } },
  );
  await app.listen();
}
bootstrap();

this is my expense-summery.module.ts

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      validationSchema: configValidationSchema,
      envFilePath: './apps/expense-summery/.env',
    }),
    CacheModule.register<RedisClientOptions>({
      store: redisStore,

      // Store-specific configuration:
      host: 'localhost',
      port: 6379,
    }),

    // DatabaseModule,
  ],
  controllers: [ExpenseSummeryController],
  providers: [ExpenseSummeryService],
})
export class ExpenseSummeryModule {}

and this is my controller

@Injectable()
export class ExpenseSummeryService {
  private readonly expenses: any[] = [];
  constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {}
  getHello(): string {
    return 'Hello World!';
  }

  async handleExpenseSummery(data: ExpenseSummeryEvent) {
    this.expenses.push(data.result);
    await this.cacheManager.set('key', 'value');
    console.log('handleExpenseSummery - EXPENSE', data);
  }

  async getExpenses() {
    const value = await this.cacheManager.get('key');
    console.log(value);

    return this.expenses;
  }
}

the log is working and i see the value but on the redis-cli i cant see anything

thanks for help with that !

timid turret
#

Try changing the CacheModule registration like this:

import { CacheModule, Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { redisStore } from 'cache-manager-redis-yet';

@Module({
  imports: [
    CacheModule.registerAsync({
      useFactory: async () => ({
        store: await redisStore({ ttl: 5000 /* add host and port options here */ }),
      }),
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
sage yew
#

I've got the same exact phenomena and must also admit, I'm just using Redis for the first time "properly". The cache works from the app, but stored keys aren't showing up in RedisInsight with my "admin" user. Very strange. I can even see the "SET" and "GET" commands being called by the app in the profiler, but no keys are showing up where I should be able to see them. It's as if the client connection is partitioning the data, so only the client can access its saved keys. Hmm..... 🤔

timid turret
#

Hmm. Just tested with redis 7 running in docker with default configuration, and I can see all of these:

  • monitor in redis-cli shows all the instructions from cache-manager
  • keys * shows all the keys
  • info keyspace shows the correct number of keys
#

Could you try it actually fails when you stop redis? I remember seeing that cacheManager used in-memory storage even though I thought it's configured to use redis.

zealous wedge
sage yew
#

@zealous wedge - I don't have such a selection available. That's another stange thing. I'm running a cluster with Sentinel, but connecting with Insight doesn't work, when selecting Sentinel. So, I'm sort of led to believe something isn't quite right with how I'm connecting with Insight.

mossy dawn
#

Hey , for me the it was working but i have ttl of 5 miliseconds , that why i couldnt see it on the redis-cli because while i moved to the redis its already deleted

zealous wedge
zealous wedge
sage yew
#

@zealous wedge - After doing some more research, I've found out that the node-redis package doesn't support Sentinel. 🙄 I've also learned that to access Sentinel (in my k8s cluster) I have to use a different port. And when I do that, I can't get access. 🤦🏻‍♂️ So, either I need to change my Redis implementation to standalone and worry about HA later or switch to ioredis as the client and see if I can get that going as a cache client. I'm pretty sure I'll also still need to figure out why I can't pass Sentinel's auth process. Hmmm. Decisions, decisions.... 🤔

zealous wedge
sage yew
#

@zealous wedge - No I haven't. I'm now trying to implement Redis Cluster. It also has HA. 🙂

sage yew
#

@zealous wedge - I got a cluster running, but couldn't figure out how to connect. So, I've gone another route. I've gotten rid of Sentinel on the cluster I had initially and now it is just a master with two replica cluster. Everything is working as it should in my app. However, I still can't see keys from the app in Insight. I'll work on HA for Redis and seeing cached values in Insight at some later point in time, when I actually need it. Thanks for helping nonetheless. 👍🏻

zealous wedge
sage yew
#

@zealous wedge - hahahaha.. .OMG!!! 🤦🏻‍♂️ It was the TTL. I thought our cache TTL was 30 minutes, when in fact it was 30 milliseconds. I'm fast, but not that fast. Hahahaha.....