Socket
Socket
Sign inDemoInstall

redis-rank

Package Overview
Dependencies
14
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.0 to 1.4.0

6

dist/Leaderboard.d.ts

@@ -45,2 +45,8 @@ import { Redis, KeyType, Pipeline } from 'ioredis';

/**
* @see incr
*
* Uses IORedis.Pipeline to be able to batch multiple commands
*/
incrMulti(id: ID, amount: number, pipeline: Pipeline): Pipeline;
/**
* Removes an entry from the leaderboard

@@ -47,0 +53,0 @@ */

@@ -96,2 +96,10 @@ "use strict";

/**
* @see incr
*
* Uses IORedis.Pipeline to be able to batch multiple commands
*/
Leaderboard.prototype.incrMulti = function (id, amount, pipeline) {
return pipeline.zincrby(this.options.path, amount, id);
};
/**
* Removes an entry from the leaderboard

@@ -98,0 +106,0 @@ */

@@ -72,2 +72,24 @@ import { Redis } from 'ioredis';

/**
* Increments an entry present in multiple leaderboards in the matrix
*
* e.g.
*
* ```
* incr('id', {
* feature1: 8,
* feature2: 5
* }, ['dimension1', 'dimension2'])
* ```
*
* Note: if a feature/dimension is invalid, the combination is ignored
* Note: if the entry is not present in the leaderboard, it is created
*
* @param features key-value object with features as key and the value to increment as value
* @param dimensions if provided, insertion will only occur on the provided dimensions.
* if not provided, all dimensions are used
*/
incr(id: ID, features: {
[key: string]: number;
}, dimensions?: string[]): Promise<void>;
/**
* Retrieve an entry from the leaderboard

@@ -74,0 +96,0 @@ *

38

dist/LeaderboardMatrix.js

@@ -120,2 +120,38 @@ "use strict";

/**
* Increments an entry present in multiple leaderboards in the matrix
*
* e.g.
*
* ```
* incr('id', {
* feature1: 8,
* feature2: 5
* }, ['dimension1', 'dimension2'])
* ```
*
* Note: if a feature/dimension is invalid, the combination is ignored
* Note: if the entry is not present in the leaderboard, it is created
*
* @param features key-value object with features as key and the value to increment as value
* @param dimensions if provided, insertion will only occur on the provided dimensions.
* if not provided, all dimensions are used
*/
LeaderboardMatrix.prototype.incr = function (id, features, dimensions) {
if (dimensions === void 0) { dimensions = []; }
if (dimensions.length == 0) { // use all dimensions
dimensions = this.options.dimensions.map(function (dim) { return dim.name; });
}
var pipeline = this.client.multi();
for (var _i = 0, dimensions_2 = dimensions; _i < dimensions_2.length; _i++) {
var dimension = dimensions_2[_i];
for (var feature in features) {
var lb = this.get(dimension, feature);
if (lb) {
pipeline = lb.incrMulti(id, features[feature], pipeline);
}
}
}
return pipeline.exec();
};
/**
* Retrieve an entry from the leaderboard

@@ -133,3 +169,3 @@ *

if (!feature) return [3 /*break*/, 2];
return [4 /*yield*/, this.around(dimension, feature, id, 1, false)];
return [4 /*yield*/, this.around(dimension, feature, id, 0, false)];
case 1:

@@ -136,0 +172,0 @@ list = _a.sent();

4

package.json
{
"name": "redis-rank",
"version": "1.3.0",
"version": "1.4.0",
"description": "Back-end to generate and manage leaderboards using Redis. Written in TypeScript and Promise-based.",

@@ -29,3 +29,3 @@ "keywords": [

"build": "tsc && cpx src/common.lua dist",
"prepare": "npm run test && npm run build",
"publish": "npm run test && npm run build && npm publish",
"test": "jest --coverage --verbose --runInBand",

@@ -32,0 +32,0 @@ "dev": "nodemon --exec \"npm run test\" --watch src --watch tests -e ts,tsx"

@@ -219,2 +219,17 @@ # redis-rank

);
// also incr works
mlb.incr(
"pepe",
{
kills: 3,
coins: 5,
time: 9
}, [
'global',
'monthly',
'weekly',
'daily',
]
);
```

@@ -221,0 +236,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc