Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace deprecated redis.setex with redis.set method #1191

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cachers/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class RedisCacher extends BaseCacher {

let p;
if (ttl) {
p = this.client.setex(this.prefix + key, ttl, data);
p = this.client.set(this.prefix + key, data, "EX", ttl);
} else {
p = this.client.set(this.prefix + key, data);
}
Expand Down
16 changes: 8 additions & 8 deletions test/unit/cachers/redis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Redis.mockImplementation(() => {
subscribe: jest.fn(),
publish: jest.fn(),
quit: jest.fn(),
setex: jest.fn(),
set: jest.fn(),

onCallbacks
};
Expand Down Expand Up @@ -320,7 +320,6 @@ describe("Test RedisCacher set & get without prefix", () => {
prefix + key,
cacher.serializer.serialize(data1)
);
expect(cacher.client.setex).toHaveBeenCalledTimes(0);
});

it("should call client.getBuffer with key & return with data1", () => {
Expand Down Expand Up @@ -439,16 +438,17 @@ describe("Test RedisCacher set & get with namespace & ttl", () => {
cacher.logger[level].mockClear()
);

cacher.client.setex = jest.fn(() => Promise.resolve());
cacher.client.set = jest.fn(() => Promise.resolve());
});

it("should call client.setex with key & data", () => {
it("should call client.set with key & data", () => {
cacher.set(key, data1);
expect(cacher.client.setex).toHaveBeenCalledTimes(1);
expect(cacher.client.setex).toHaveBeenCalledWith(
expect(cacher.client.set).toHaveBeenCalledTimes(1);
expect(cacher.client.set).toHaveBeenCalledWith(
prefix + key,
60,
cacher.serializer.serialize(data1)
cacher.serializer.serialize(data1),
"EX",
60
);
});

Expand Down