1: <?php namespace Laravel\Cache\Drivers;
2:
3: class Redis extends Driver {
4:
5: /**
6: * The Redis database instance.
7: *
8: * @var Laravel\Redis
9: */
10: protected $redis;
11:
12: /**
13: * Create a new Redis cache driver instance.
14: *
15: * @param Laravel\Redis $redis
16: * @return void
17: */
18: public function __construct(\Laravel\Redis $redis)
19: {
20: $this->redis = $redis;
21: }
22:
23: /**
24: * Determine if an item exists in the cache.
25: *
26: * @param string $key
27: * @return bool
28: */
29: public function has($key)
30: {
31: return ( ! is_null($this->redis->get($key)));
32: }
33:
34: /**
35: * Retrieve an item from the cache driver.
36: *
37: * @param string $key
38: * @return mixed
39: */
40: protected function retrieve($key)
41: {
42: if ( ! is_null($cache = $this->redis->get($key)))
43: {
44: return unserialize($cache);
45: }
46: }
47:
48: /**
49: * Write an item to the cache for a given number of minutes.
50: *
51: * <code>
52: * // Put an item in the cache for 15 minutes
53: * Cache::put('name', 'Taylor', 15);
54: * </code>
55: *
56: * @param string $key
57: * @param mixed $value
58: * @param int $minutes
59: * @return void
60: */
61: public function put($key, $value, $minutes)
62: {
63: $this->forever($key, $value);
64:
65: $this->redis->expire($key, $minutes * 60);
66: }
67:
68: /**
69: * Write an item to the cache that lasts forever.
70: *
71: * @param string $key
72: * @param mixed $value
73: * @return void
74: */
75: public function forever($key, $value)
76: {
77: $this->redis->set($key, serialize($value));
78: }
79:
80: /**
81: * Delete an item from the cache.
82: *
83: * @param string $key
84: * @return void
85: */
86: public function forget($key)
87: {
88: $this->redis->del($key);
89: }
90:
91: /**
92: * Flush the entire cache.
93: *
94: * @return void
95: */
96: public function flush()
97: {
98: $this->redis->flushdb();
99: }
100:
101: }
102: