我想知道是否有巧妙的方法在 Redis 键过期后测试其行为。我正在为我的应用程序构建一个小型的 Redis 缓存,并希望测试当 Redis 键过期时会发生什么。
我使用 rspec 作为测试框架。我尝试使用 Timecop 在测试期间更改时间,但意识到这只会影响测试框架而不是外部的 Redis 服务器。
我可以将 TTL 设置为 1,然后使用 sleep(1),但我不想在测试中引入睡眠。
是否有人有好的测试方法?
我想知道是否有巧妙的方法在 Redis 键过期后测试其行为。我正在为我的应用程序构建一个小型的 Redis 缓存,并希望测试当 Redis 键过期时会发生什么。
我使用 rspec 作为测试框架。我尝试使用 Timecop 在测试期间更改时间,但意识到这只会影响测试框架而不是外部的 Redis 服务器。
我可以将 TTL 设置为 1,然后使用 sleep(1),但我不想在测试中引入睡眠。
是否有人有好的测试方法?
redis_client.should_receive(:ttl).with(key).then_return(-1)
redis_client.should_receive(:get).with(key).then_return(nil)
expect(redis_client).to receive(:get).with(key).and_return(value)