npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nest-public/nest-redis

v1.0.2

Published

nest.js框架Redis插件

Downloads

3

Readme

npm version

nest-redis

Nest 框架Redis插件 封装了一些redis常用操作

安装

$ npm install @nest-public/nest-redis --save

用法

config.js 配置 具体请参考ioredis

// 单客户端
export const config = {
	port: 6379,
	host: 'xxx.xxxx.xxx',
	password: 'xxxxxxxxxxxxxxxxxx',
	db: 0
};

// 集群配置
export const config = {
	cluster: true,
	nodes: [
		{
			port: 6379,
			host: 'xxx.xxxx.xxx',
			password: 'xxxxxxxxxxxxxxxxxx',
			db: 0
		},
		{
			port: 6379,
			host: 'xxx.xxxx.xxx',
			password: 'xxxxxxxxxxxxxxxxxx',
			db: 0
		}
	],
	option: {
		// ioredis集群设置
	}
}

module.ts

import { AppController } from './test.controller';
import { RedisModule } from '@nest-public/nest-redis';
import { config } from '../config/config.js';

@Module({
	imports: [ 
		RedisModule.forRoot(config)
	],
	controllers: [AppController],
})

export class AppModule{}

controller.ts

import { Controller, Req, Post, Get, UseInterceptors, UploadedFiles } from '@nestjs/common';
import { FilesInterceptor } from '@nestjs/platform-express';
import { OSS } from '@nest-public/nest-oss';

/**
 * AppController
 * @export
 * @class AppController
 */
@Controller()
export class AppController {
	constructor(private readonly oss: OSS) {}

	/**
	 * 设置key
	 */
	@Get('setKey')
	public async setKey() {
		const result = await this.redis.set(`testkey`, 'this is a test meassage', 600); // set(key:string, data:any, ttl?:number); ttl默认3600秒 成功返回 'OK'

		return result;
	}

	/**
	 * 获取key
	 */
	@Get('getKey')
	public async getKey() {
		const result = await this.redis.get('testkey'); // get(key: string);

		return result;
	}

	/**
	 * 效验key是否存在
	 */
	@Get('exists')
	public async exists() {
		const result = await this.redis.exists('testkey'); // exists(key: string); 成功返回 1

		return result;
	}

	/**
	 * 设置到期时间
	 */
	@Get('expire')
	public async expire() {
		const result = await this.redis.expire('testkey', 5600); // expire(key: string, time: number); 成功返回 1

		return result;
	}

	/**
	 * 设置key永不过期
	 */
	@Get('persist')
	public async persist() {
		const result = await this.redis.persist('testkey'); // persist(key: string); 成功返回 1

		return result;
	}

	/**
	 * 删除key
	 */
	@Get('del')
	public async del() {
		const result = await this.redis.del('testkey'); // del(key: string); 成功返回 1

		return result;
	}
}

测试

进行单元测试前请先配置好 test.module.ts 里面的redis配置

# jest tests
$ npm run test