Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updating readme & cleaning redis-ztriml

  • Loading branch information...
commit 6f271872de35b83476b4bec15959d1431ec3a9d0 1 parent aeed683
Francois-Guillaume Ribreau authored

Showing 2 changed files with 39 additions and 8 deletions. Show diff stats Hide diff stats

  1. +36 4 README.md
  2. +3 4 bin/redis-ztrim
40 README.md
Source Rendered
@@ -6,17 +6,51 @@
6 6
7 7 ## Documentation
8 8
  9 +* [redis-ztrim](#ztrim)
9 10 * [redis-zlist-size](#zlist-size)
10 11 * [redis-rename](#rename)
11 12 * [redis-delall](#delall)
12 13
  14 +<a name="ztrim" />
  15 +### Redis-ztrim
  16 +
  17 +```
  18 +Usage: node ./bin/redis-ztrim [options] pattern start stop
  19 +
  20 +Trim a group of zlists matching `pattern` so that they'll contain only the specified range of elements specified. Both start and stop are zero-based indexes, where 0 is the first element of the list with the highest score (the head), 1 the next element and so on.
  21 +
  22 +For example: redis-ztrim foobar* 0 2 will modify the zsets matching the pattern foobar* so that only the first three elements of each zsets will remain.
  23 +
  24 +Options:
  25 + -p, --preview preview what is going to be deleted [boolean] [default: false]
  26 + -v, --verbose verbose mode [boolean] [default: false]
  27 + -h, --help this message. [boolean]
  28 +```
  29 +
  30 +Trim all zsets matching the pattern `bringr:*:*:ua:*" so that only their members ranked from 0 to 99 will remain.
  31 +```shell
  32 +$ redis-ztrim
  33 +✔ bringr:1:121:ua:m trimmed
  34 +✔ bringr:1:121:ua:y trimmed
  35 +✔ bringr:1:123:ua:y trimmed
  36 +✔ bringr:1:123:ua:m trimmed
  37 +✔ bringr:1:121:ua:d trimmed
  38 +✔ bringr:1:123:ua:d trimmed
  39 +✔ bringr:6:93:ua:y trimmed
  40 +✔ bringr:6:93:ua:m trimmed
  41 +✔ bringr:1:123:ua:h trimmed
  42 +✔ bringr:6:93:ua:d trimmed
  43 +[... truncated ... ]
  44 +```
  45 +
  46 +
13 47 <a name="zlist-size" />
14 48 ### Redis-zlist-size
15 49
16 50 ```
17 51 Retrieve a list of zset keys via `pattern` and order them by size
18 52
19   -Usage: node ./redis-zlist-size [options] pattern
  53 +Usage: redis-zlist-size [options] pattern
20 54
21 55 Options:
22 56 --json print results in JSON format [default: false]
@@ -26,7 +60,7 @@ Options:
26 60 ```
27 61
28 62 ```shell
29   -$ redis-zlist-size "bringr:*:*:tc:*"
  63 +$ redis-zlist-size "bringr:*:*:ua:*"
30 64 bringr:1:121:ua:m Members 15821544 Size 81660
31 65 bringr:1:121:ua:y Members 15821544 Size 81660
32 66 bringr:1:123:ua:y Members 13782356 Size 66280
@@ -37,8 +71,6 @@ bringr:6:93:ua:y Members 10138538 Size 52129
37 71 bringr:6:93:ua:m Members 10138538 Size 52129
38 72 bringr:1:123:ua:h Members 9192799 Size 44231
39 73 bringr:6:93:ua:d Members 6720535 Size 34702
40   -bringr:1:123:ua:h Members 3112684 Size 14940
41   -bringr:1:121:ua:d Members 2248963 Size 12071
42 74 [... truncated ... ]
43 75 ```
44 76
7 bin/redis-ztrim
@@ -17,8 +17,8 @@ For example: redis-ztrim foobar* 0 2 will modify the zsets matching the pattern
17 17 , start = argv._[1]
18 18 , stop = argv._[2];
19 19
20   -if(argv.h || argv._.length != 3 || start != 0){
21   - if(start != 0){console.error('Unsupported: start should be 0.')}
  20 +if(argv.h || argv._.length < 1 || argv._.length > 1 && (stop == undefined || start != undefined && start != 0)){
  21 + if(argv._.length > 1 && start != 0){console.error('Unsupported: start should be 0.')}
22 22 return arg.showHelp(console.error);
23 23 }
24 24
@@ -27,12 +27,11 @@ function trimKeys(keys){
27 27
28 28 function fnIter(){
29 29
30   - // ZREMRANGEBYRANK a 0 -2
31 30 var args = ['zremrangebyrank', keys[i], 0, -stop-1];
32 31
33 32 r.redisCli(args, function(res){
34 33 if(!isNaN(parseInt(res, 10))){
35   - argv.verbose && console.log('✔ ', keys[i], 'trimmed');
  34 + argv.verbose && console.log('✔ ', keys[i], ,"\t", 'trimmed');
36 35 return fnDone();
37 36 }
38 37

0 comments on commit 6f27187

Please sign in to comment.
Something went wrong with that request. Please try again.