
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
redis-extend
Advanced tools
Extend some function utility for redis client. Somehow solve the problem expire field in hash/member in hash/set/sorted-set.
example issue: issue since 2011 Implement Expire on hash
issue since 2013 Allow to set an expiration on hash field
etc ...
All bugs please create issue on github or send to my email Chickyky@gmail
$ npm run test
See file test for example and run cmd for test.
Image result test:

Extend from ioredis then create new Redis client with all feature of ioredis and add some function helper like hexpire/sexpire/zexpire/...
This package create mini job in background clear field/member expired of hash/set/sorted-set, find the exact next time to remove and use setTimeout function to schedule remove.
When remove expired field/member success, it will emit a event expired.
$ npm install redis-extend
const Redis = require('redis-extend');
const redis = new Redis('redis://localhost:6379');
redis.on('zexpired', (data) => {
console.log(`\n**************
--> [zexpired] data:`, data, `
****************\n`);
});
;(async () => {
let zResult = await redis.zadd('myzset', 10, 'one');
let score = await redis.zscore('myzset', 'one');
let isZMember = await redis.zismember('myzset', 'one');
console.log('zResult=', zResult, 'score=', score, 'isZMember=', isZMember);
isZMember = await redis.zismember('myzset', 'two');
console.log('isZMember=', isZMember);
let zmismember = await redis.zmismember('myzset', 'one', 'two');
console.log('zmismember=', zmismember);
zmismember = await redis.zmismember('myzset', ['one', 'two']);
console.log('zmismember=', zmismember);
let zmembers = await redis.zmembers('myzset');
console.log('zmembers=', zmembers);
let zexpire = await redis.zexpire('myzset', 'one', 5);
console.log('zexpire=', zexpire);
let zpttl = await redis.zpttl('myzset', 'one');
console.log('zpttl=', zpttl);
})()
/* output like this:
zResult= 1 score= 10 isZMember= 1
isZMember= 0
zmismember= [ 1, 0 ]
zmismember= [ 1, 0 ]
zmembers= [ 'one' ]
zexpire= 1
zpttl= 4996
**************
--> [zexpired] data: {
type: 'zset',
key: 'myzset',
member: 'one',
expiredAt: 1619853480176
}
****************
*/
When a new Redis instance is created,
a connection to Redis will be created at the same time.
You can specify which Redis to connect to by:
new Redis(); // Connect to 127.0.0.1:6379
new Redis(6380); // 127.0.0.1:6380
new Redis(6379, "192.168.1.1"); // 192.168.1.1:6379
new Redis("/tmp/redis.sock");
new Redis({
port: 6379, // Redis port
host: "127.0.0.1", // Redis host
family: 4, // 4 (IPv4) or 6 (IPv6)
password: "auth",
db: 0,
});
You can also specify connection options as a redis:// URL or rediss:// URL when using TLS encryption:
// Connect to 127.0.0.1:6380, db 4, using password "authpassword":
new Redis("redis://:authpassword@127.0.0.1:6380/4");
// Username can also be passed via URI.
// It's worth to noticing that for compatibility reasons `allowUsernameInURI`
// need to be provided, otherwise the username part will be ignored.
new Redis(
"redis://username:authpassword@127.0.0.1:6380/4?allowUsernameInURI=true"
);
See API Documentation for all available options.
returns a promise if the last argument isn't a function (no callback)
call a redis command with name and dynamic parameter.
redis.command('GET', 'Chickyky', (err, value) => {
console.log('command GET result=', value);
});
set expire for field in hash/set/sorted-set key in seconds
same as hexpire/sexpire/zexpire but expire in milliseconds
same sismember, return integer:
1 if the element is a member of the set.0 if the element is not a member of the set, or if key does not exist.same smismember, list representing the membership of the given elements, in the same order as they are requested.
let zmismember = await redis.zmismember('myzset', 'one', 'two');
console.log('zmismember=', zmismember);
/* output:
zmismember= [ 1, 0 ]
*/
same smembers, return all elements of the sorted-set.
Return TTL (Time ti live) in seconds, or a negative value in order to signal an error, corresponding to hash/set/sorted-set.
-2 if the key does not exist.-1 if the key exists but has no associated expire.same httt/sttl/ztt/ but Return TTL in milliseconds.
Batch delete keys by pattern.
options:
count (number): limit each delete batch, default 10.type (enum string): string/hash/set/zset delete with type of key which you want, default is delete all type.Like pdel but delete fields/members in hash/set/zset
options:
count (number): limit each delete batch, default 10.Set Nested JSON into hash with your key.
Note: type of field is
primitive type:
- string
- number
- boolean
- null
- undefined
- instance of Date
Get Nested JSON with your key set by jset
example:
const nestedObj = {
a: 'aaaa:bbbb',
b: new Date(2021, 7, 7),
c: false,
d: 1,
e: {
a: 'aaaa:bbbb',
b: new Date(2021, 7, 7),
c: true,
d: 1,
f: null,
g: undefined,
h: {
a: 'aaaa:bbbb',
b: new Date(2021, 7, 7),
c: true,
d: 1,
f: null,
g: undefined,
h: ['aaa', 123, false, true, false, new Date(2021, 7, 7), null, undefined]
}
},
f: null,
g: undefined,
h: ['aaa', 123, false, true, false, new Date(2021, 7, 7), null, undefined]
}
;(async () => {
let jset = await redis.jset('jest_jset_nested_obj', nestedObj);
let jget = await redis.jget('jest_jset_nested_obj');
})()
This nested JSON will set in Redis Hash like (run cmd in terminal):
127.0.0.1:6379[15]> hgetall jest_jset_nested_obj
1) "a"
2) "s:aaaa:bbbb"
3) "b"
4) "d:2021-08-06T17:00:00.000Z"
5) "c"
6) "b:false"
7) "d"
8) "n:1"
9) "e.a"
10) "s:aaaa:bbbb"
11) "e.b"
12) "d:2021-08-06T17:00:00.000Z"
13) "e.c"
14) "b:true"
15) "e.d"
16) "n:1"
17) "e.f"
18) "nu"
19) "e.g"
20) "u"
21) "e.h.a"
22) "s:aaaa:bbbb"
23) "e.h.b"
24) "d:2021-08-06T17:00:00.000Z"
25) "e.h.c"
26) "b:true"
27) "e.h.d"
28) "n:1"
29) "e.h.f"
30) "nu"
31) "e.h.g"
32) "u"
33) "e.h.h.0"
34) "s:aaa"
35) "e.h.h.1"
36) "n:123"
37) "e.h.h.2"
38) "b:false"
39) "e.h.h.3"
40) "b:true"
41) "e.h.h.4"
42) "b:false"
43) "e.h.h.5"
44) "d:2021-08-06T17:00:00.000Z"
45) "e.h.h.6"
46) "nu"
47) "e.h.h.7"
48) "u"
49) "f"
50) "nu"
51) "g"
52) "u"
53) "h.0"
54) "s:aaa"
55) "h.1"
56) "n:123"
57) "h.2"
58) "b:false"
59) "h.3"
60) "b:true"
61) "h.4"
62) "b:false"
63) "h.5"
64) "d:2021-08-06T17:00:00.000Z"
65) "h.6"
66) "nu"
67) "h.7"
68) "u"
| Event | Description |
|---|---|
| expired | Emit when one expired field/member was removed successful, include key expired by command expire |
| hexpired | Emit when a expired field in hash was removed successful |
| sexpired | Emit when a expired member in set was removed successful |
| zexpired | Emit when a expired member in sorted set was removed successful |
| keyspace | This is Key-space notification, read more Redis Keyspace Notifications |
| keyevent | This is Key-event notification, read more Redis Keyspace Notifications |
Event expired/hexpired/sexpired/zexpired:
field and set/zset is member): name of field/member expired.Event keyevent:
Event keyspace:
Example data of event:
redis.on('zexpired', (data) => {
console.log(`\n**************
--> [zexpired] data:`, data, `
****************\n`);
});
redis.on('keyevent', (data) => {
console.log(`\n**************
--> [keyevent] data:`, data, `
****************\n`);
});
/* output
**************
--> [zexpired] data: {
type: 'zset',
key: 'myzset',
member: 'one',
expiredAt: 1619853480176
}
****************
**************
--> [keyevent] data: {
channel: 'keyevent',
db: 0,
event: 'expired',
key: '__redis-extend:ttl:zset:myzset:one'
}
****************
*/
FAQs
support some function like expire field in hash set
We found that redis-extend demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.