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

egg-xc-redis

v1.1.7

Published

redis utils for egg

Downloads

14

Readme

egg-xc-redis

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-xc-redis --save

Usage

// {app_root}/config/plugin.js
exports.xcRedis = {
  enable: true,
  package: 'egg-xc-redis',
};

Configuration

// {app_root}/config/config.default.js
exports.xcRedis = {
  {
  clients: {
    db1: { // instanceName. See below
      port: 6379, // Redis port
      host: 'localhost', // Redis host
      password: '',
      db: 1,
    },
    db2: {
      port: 6379,
      host: 'localhost',
      password: '',
      db: 2,
    },
  },
};
针对配置可覆盖

see config/config.default.js for more detail. ##API

 //获取redis链接 默认配置为db1
app.redis.getConn()

//获取链接实例 db为 db1,db2这种key值
app.redis.getConnInstance(db)

//释放redis链接 conn为redis链接
app.redis.doRelease(conn)

//统一设置赋值 conn为redis链接  key为键  
//value为string或object 
//value为string时
//subvalue为undefined则value为存储的值
//subvalue不为undefined则value为key对应对象的键,subvalue为该键的值
app.redis.set(conn, key, value,subvalue)

//统一获取值 conn为redis链接  key为键
// isObject和objectKey为undefined 时获取字符串值
// isObject为true,objectKey为undefined 时获取对象
// isObject为true,objectKey不为为undefined 时获取对象中objectKey对应的值
app.redis.get(conn, key,isObject, objectKey) 

 // 设置一个key的过期的秒数
app.redis.expire(conn, key, seconds)

// 查询一个key是否存在
app.redis.exists(conn, key)

//删除key
app.redis.del(conn, key)

//clear all keys
app.redis.flushdb(conn)

Example

赋值获取值

    const conn = app.redis.getConn();
    await app.redis.set(conn, 'name', 'xiaoming');
    const result = await app.redis.get(conn, 'name');
    assert.equal(result, 'xiaoming');
    app.redis.doRelease(conn);

赋值获取对象

   const conn = app.redis.getConn();
    await app.redis.set(conn, 'nameObj', { age: 12, job: 'programer' });
    const result = await app.redis.get(conn, 'nameObj', true,'job');
    app.logger.info('shoud get result get obj', result);
    assert.equal(result, 'programer');
    app.redis.doRelease(conn);

Questions & Suggestions

Please open an issue here.

License

MIT