Subversion-Projekte lars-tiefland.ci

Revision

Revision 2257 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 2257 Revision 2414
Zeile 4... Zeile 4...
4
 *
4
 *
5
 * An open source application development framework for PHP
5
 * An open source application development framework for PHP
6
 *
6
 *
7
 * This content is released under the MIT License (MIT)
7
 * This content is released under the MIT License (MIT)
8
 *
8
 *
9
 * Copyright (c) 2014 - 2018, British Columbia Institute of Technology
9
 * Copyright (c) 2014 - 2019, British Columbia Institute of Technology
10
 *
10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Zeile 27... Zeile 27...
27
 * THE SOFTWARE.
27
 * THE SOFTWARE.
28
 *
28
 *
29
 * @package	CodeIgniter
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32
 * @copyright	Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
32
 * @copyright	Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
33
 * @license	http://opensource.org/licenses/MIT	MIT License
33
 * @license	https://opensource.org/licenses/MIT	MIT License
34
 * @link	https://codeigniter.com
34
 * @link	https://codeigniter.com
35
 * @since	Version 3.0.0
35
 * @since	Version 3.0.0
36
 * @filesource
36
 * @filesource
37
 */
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
38
defined('BASEPATH') OR exit('No direct script access allowed');
Zeile 74... Zeile 74...
74
	 *
74
	 *
75
	 * @var	array
75
	 * @var	array
76
	 */
76
	 */
77
	protected $_serialized = array();
77
	protected $_serialized = array();
Zeile -... Zeile 78...
-
 
78
 
-
 
79
	/**
-
 
80
	 * del()/delete() method name depending on phpRedis version
-
 
81
	 *
-
 
82
	 * @var	string
-
 
83
	 */
-
 
84
	protected static $_delete_name;
78
 
85
 
Zeile 79... Zeile 86...
79
	// ------------------------------------------------------------------------
86
	// ------------------------------------------------------------------------
80
 
87
 
81
	/**
88
	/**
Zeile 95... Zeile 102...
95
		{
102
		{
96
			log_message('error', 'Cache: Failed to create Redis object; extension not loaded?');
103
			log_message('error', 'Cache: Failed to create Redis object; extension not loaded?');
97
			return;
104
			return;
98
		}
105
		}
Zeile -... Zeile 106...
-
 
106
 
-
 
107
		isset(static::$_delete_name) OR static::$_delete_name = version_compare(phpversion('phpredis'), '5', '>=')
-
 
108
			? 'del'
-
 
109
			: 'delete';
99
 
110
 
Zeile 100... Zeile 111...
100
		$CI =& get_instance();
111
		$CI =& get_instance();
101
 
112
 
102
		if ($CI->config->load('redis', TRUE, TRUE))
113
		if ($CI->config->load('redis', TRUE, TRUE))
Zeile 133... Zeile 144...
133
		}
144
		}
134
		catch (RedisException $e)
145
		catch (RedisException $e)
135
		{
146
		{
136
			log_message('error', 'Cache: Redis connection refused ('.$e->getMessage().')');
147
			log_message('error', 'Cache: Redis connection refused ('.$e->getMessage().')');
137
		}
148
		}
138
 
-
 
139
		// Initialize the index of serialized values.
-
 
140
		$serialized = $this->_redis->sMembers('_ci_redis_serialized');
-
 
141
		empty($serialized) OR $this->_serialized = array_flip($serialized);
-
 
142
	}
149
	}
Zeile 143... Zeile 150...
143
 
150
 
Zeile 144... Zeile 151...
144
	// ------------------------------------------------------------------------
151
	// ------------------------------------------------------------------------
Zeile 151... Zeile 158...
151
	 */
158
	 */
152
	public function get($key)
159
	public function get($key)
153
	{
160
	{
154
		$value = $this->_redis->get($key);
161
		$value = $this->_redis->get($key);
Zeile 155... Zeile 162...
155
 
162
 
156
		if ($value !== FALSE && isset($this->_serialized[$key]))
163
		if ($value !== FALSE && $this->_redis->sIsMember('_ci_redis_serialized', $key))
157
		{
164
		{
158
			return unserialize($value);
165
			return unserialize($value);
Zeile 159... Zeile 166...
159
		}
166
		}
Zeile 182... Zeile 189...
182
			}
189
			}
Zeile 183... Zeile 190...
183
 
190
 
184
			isset($this->_serialized[$id]) OR $this->_serialized[$id] = TRUE;
191
			isset($this->_serialized[$id]) OR $this->_serialized[$id] = TRUE;
185
			$data = serialize($data);
192
			$data = serialize($data);
186
		}
193
		}
187
		elseif (isset($this->_serialized[$id]))
194
		else
188
		{
-
 
189
			$this->_serialized[$id] = NULL;
195
		{
190
			$this->_redis->sRemove('_ci_redis_serialized', $id);
196
			$this->_redis->sRemove('_ci_redis_serialized', $id);
Zeile 191... Zeile 197...
191
		}
197
		}
192
 
198
 
Zeile 201... Zeile 207...
201
	 * @param	string	$key	Cache key
207
	 * @param	string	$key	Cache key
202
	 * @return	bool
208
	 * @return	bool
203
	 */
209
	 */
204
	public function delete($key)
210
	public function delete($key)
205
	{
211
	{
206
		if ($this->_redis->delete($key) !== 1)
212
		if ($this->_redis->{static::$_delete_name}($key) !== 1)
207
		{
213
		{
208
			return FALSE;
214
			return FALSE;
209
		}
215
		}
Zeile 210... Zeile -...
210
 
-
 
211
		if (isset($this->_serialized[$key]))
-
 
212
		{
-
 
213
			$this->_serialized[$key] = NULL;
216
 
214
			$this->_redis->sRemove('_ci_redis_serialized', $key);
-
 
Zeile 215... Zeile 217...
215
		}
217
		$this->_redis->sRemove('_ci_redis_serialized', $key);
216
 
218
 
Zeile 217... Zeile 219...
217
		return TRUE;
219
		return TRUE;
Zeile 226... Zeile 228...
226
	 * @param	int	$offset	Step/value to add
228
	 * @param	int	$offset	Step/value to add
227
	 * @return	mixed	New value on success or FALSE on failure
229
	 * @return	mixed	New value on success or FALSE on failure
228
	 */
230
	 */
229
	public function increment($id, $offset = 1)
231
	public function increment($id, $offset = 1)
230
	{
232
	{
231
		return $this->_redis->incr($id, $offset);
233
		return $this->_redis->incrBy($id, $offset);
232
	}
234
	}
Zeile 233... Zeile 235...
233
 
235
 
Zeile 234... Zeile 236...
234
	// ------------------------------------------------------------------------
236
	// ------------------------------------------------------------------------
Zeile 240... Zeile 242...
240
	 * @param	int	$offset	Step/value to reduce by
242
	 * @param	int	$offset	Step/value to reduce by
241
	 * @return	mixed	New value on success or FALSE on failure
243
	 * @return	mixed	New value on success or FALSE on failure
242
	 */
244
	 */
243
	public function decrement($id, $offset = 1)
245
	public function decrement($id, $offset = 1)
244
	{
246
	{
245
		return $this->_redis->decr($id, $offset);
247
		return $this->_redis->decrBy($id, $offset);
246
	}
248
	}
Zeile 247... Zeile 249...
247
 
249
 
Zeile 248... Zeile 250...
248
	// ------------------------------------------------------------------------
250
	// ------------------------------------------------------------------------