|
| 1 | +require "./spec_helper" |
| 2 | + |
| 3 | +describe Kemal::Cache::RedisStore do |
| 4 | + it "works against a real Redis instance" do |
| 5 | + redis_url = real_redis_url |
| 6 | + pending!("REDIS_URL is not set") unless redis_url |
| 7 | + |
| 8 | + namespace = unique_redis_namespace("kemal-cache-integration") |
| 9 | + other_namespace = unique_redis_namespace("kemal-cache-integration-other") |
| 10 | + store = Kemal::Cache::RedisStore.new(redis_url, namespace) |
| 11 | + client = Redis::Client.new(URI.parse(redis_url)) |
| 12 | + |
| 13 | + begin |
| 14 | + store.clear |
| 15 | + client.del("#{other_namespace}:keep") |
| 16 | + |
| 17 | + store.set("greeting", "hello", 50.milliseconds) |
| 18 | + store.get("greeting").should eq("hello") |
| 19 | + |
| 20 | + store.delete("greeting") |
| 21 | + store.get("greeting").should be_nil |
| 22 | + |
| 23 | + store.set("one", "1", 50.milliseconds) |
| 24 | + store.set("two", "2", 50.milliseconds) |
| 25 | + client.set("#{other_namespace}:keep", "3", ex: 50.milliseconds) |
| 26 | + store.clear |
| 27 | + |
| 28 | + store.get("one").should be_nil |
| 29 | + store.get("two").should be_nil |
| 30 | + client.get("#{other_namespace}:keep").should eq("3") |
| 31 | + |
| 32 | + store.set("short", "ttl", 5.milliseconds) |
| 33 | + sleep 10.milliseconds |
| 34 | + store.get("short").should be_nil |
| 35 | + ensure |
| 36 | + store.clear |
| 37 | + client.del("#{other_namespace}:keep") |
| 38 | + end |
| 39 | + end |
| 40 | +end |
0 commit comments