-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f6971f
commit cc02a24
Showing
5 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import util from "util"; | ||
import async from "async"; | ||
|
||
/** Delete cache entries by tag | ||
* | ||
* @method ExpressRedisCache.delTag | ||
* @description Delete entries by tag | ||
* @return null | ||
* @arg {String} name - The tag name | ||
* @arg {Function} callback | ||
*/ | ||
|
||
function delTag(name, callback) { | ||
let self = this; | ||
|
||
if (typeof name !== "string") { | ||
return this.emit( | ||
"error", | ||
new Error("ExpressRedisCache.delTag: missing first argument String") | ||
); | ||
} | ||
|
||
if (typeof callback !== "function") { | ||
return this.emit( | ||
"error", | ||
new Error("ExpressRedisCache.delTag: missing second argument Function") | ||
); | ||
} | ||
|
||
/** Get prefix */ | ||
|
||
let prefix = self.prefix.match(/:$/) | ||
? self.prefix.replace(/:$/, "") | ||
: self.prefix; | ||
|
||
/** Tell Redis to delete hash */ | ||
|
||
let redisKey = `${prefix}:${name}`; | ||
|
||
self.client.smembers(redisKey, (err, deletions) => { | ||
deletions.push(redisKey); | ||
async.each( | ||
deletions, | ||
|
||
(key, callback) => { | ||
self.client.del(key, () => { | ||
self.emit("message", util.format("DEL %s", key)); | ||
callback(); | ||
}); | ||
}, | ||
|
||
error => { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
callback(null, deletions.length); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
export default delTag; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import should from "should"; | ||
import async from "async"; | ||
import ERC from "../dist"; | ||
|
||
let prefix = process.env.EX_RE_CA_PREFIX || "erct:"; | ||
let host = process.env.EX_RE_CA_HOST || "localhost"; | ||
let port = process.env.EX_RE_CA_PORT || 6379; | ||
|
||
const cache = new ERC({ | ||
prefix: prefix, | ||
host: host, | ||
port: port | ||
}); | ||
|
||
describe("delTag", () => { | ||
before(done => { | ||
cache.add( | ||
"tag-to-del", | ||
"-", | ||
{ | ||
tag: "testtag" | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it("should be a function", () => { | ||
cache.delTag.should.be.a.Function; | ||
}); | ||
|
||
it("should callback", done => { | ||
cache.delTag("testtag", ($error, $deletions) => { | ||
debugger; | ||
done(); | ||
}); | ||
}); | ||
}); |