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

@ksfcore/kedis-helper

v2.0.6

Published

Kedis调用nodejs实现

Downloads

1

Readme

说明

Kedis是一个基于KSF框架开发的分布式NoSQL存储系统,数据采用内存存储,支持连接后端DB实现数据持久化。Kedis采用集群模式,具有高扩展、高可用的特点。

@ksfcore/kedis-helper是Kedis调用的nodejs实现。

同时从2.1.0版本开始,不再依赖Q模块,而使用原生Promise.

$ npm i @ksfcore/kedis-helper

初始化

const Kedis = require('@ksfcore/kedis-helper')
const kedisProxy = new Kedis({
  proxy: 'Kedis.ADProxyServer.ProxyObj',
  moduleName: 'ADUserProfile'
})

只需要在对应的proxy添加ip端口既可以实现通过代理方式访问

const kedisProxy = new Kedis({
  proxy: 'Kedis.ADProxyServer.ProxyObj@tcp -h 172.16.8.125 -p 8888 -t 6000',
  moduleName: 'ADUserProfile'
})

默认情况下,Kedis的rpc调用保持长连接,即每20秒会给服务端发送一个心跳,如果不想保持长连接,可以通过设置keepAlive为false来实现,例如:

const kedisProxy = new Kedis({
  keepAlive: false,
  proxy: 'Kedis.ADProxyServer.ProxyObj',
  moduleName: 'ADUserProfile'
})

调用

Kedis相关数据结构请参照 CacheShare.jceProxyShare.jce,对应的js对象分别为 cacheShareProxyproxyShareProxy

const { cacheShareProxy, proxyShareProxy } = require('@ksfcore/kedis-helper')

Kedis调用API请参照 Proxy.jce,下例将给出多个DEMO

const KsfStream = require("@ksfcore/stream")
const Kedis = require('@ksfcore/kedis-helper')
const { cacheShareProxy, proxyShareProxy } = Kedis

const kedisProxy = new Kedis({
  proxy: 'Kedis.ADProxyServer.ProxyObj@tcp -h 172.16.8.125 -p 8888 -t 6000',
  moduleName: 'ADUserProfile'
})

// 单次不带版本调用
kedisProxy.getString('testKey').then.then(console.log).catch(console.error);

// 单次不带版本写入
kedisProxy.setString('testKey', 'testValue').then(console.log).catch(console.error);


// 批量查询全量数据
const vec = new KsfStream.List(KsfStream.String)
vec.readFromObject(['testKey1', 'testKey2'])
kedisProxy.getKVBatch(vec).then(console.log).catch(console.error)
//...

指定master

如下列举两种服务调用方式:

1.http server

自由传递context上下文,参照如下httpdemo

const KsfStream = require('@ksfcore/stream')
const kedisProxy = new Kedis({
  proxy: 'Kedis.ADProxyServer.ProxyObj',
  moduleName: 'ADUserProfile',
})

const context = new KsfStream.Map(KsfStream.String, KsfStream.String)
context.insert('idcAreaSpecified', 'force-master')
// http server or other environment
kedisProxy.getKV('a', { context }).then(console.log).catch(console.error)

2.ksf server

ksf server 从当前服务的上下文中获取上下文,并进行传递 当然也支持自己构造context上下文方式(参照上述hhtp方式)

// ksf server
CRM.TestImp.prototype.test = async function (current, req, rsp) {

  // ...

  //////////// 透传context DEMO start ////////
  const context = current.getContext();
  context.insert('idcAreaSpecified', 'force-master')

  kedisProxy.getString('a', { context }).then(console.log).catch(console.error);

  //////////// 透传context DEMO end ////////

  // ...
}