Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+56 -8
View File
@@ -11,7 +11,7 @@
namespace IPS\Data\Store;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -36,24 +36,48 @@ class _Redis extends \IPS\Data\Store
* Redis key
*/
protected $_redisKey;
/**
* Constructor
*
* @param array $configuration Configuration to use
* @return void
*/
public function __construct( $configuration )
{
try
{
$connection = \IPS\Redis::i()->connection('write');
if( !$connection )
{
throw new \RedisException;
}
}
catch( \RedisException $e )
{
throw new \IPS\Data\Store\Exception;
}
}
/**
* Get random string used in the keys to identify this site compared to other sites
*
* @param string $key
* @return string|FALSE Value from the _datastore; FALSE if key doesn't exist
*/
protected function _getRedisKey()
{
if ( !$this->_redisKey )
{
if ( !( $this->_redisKey = \IPS\Redis::i()->get( 'redisKey_store' ) ) )
/* Last access ensures that the data is not stale if we fail back to MySQL and then go back to Redis later */
if ( !( $this->_redisKey = \IPS\Redis::i()->get( 'redisKey_store' ) ) OR ! \IPS\Redis::i()->get( 'redisStore_lastAccess' ) )
{
$this->_redisKey = md5( mt_rand() );
\IPS\Redis::i()->setex( 'redisKey_store', 604800, $this->_redisKey );
\IPS\Redis::i()->setex( 'redisStore_lastAccess', ( 3 * 3600 ), time() );
}
}
return $this->_redisKey . '_str_';
}
@@ -62,10 +86,15 @@ class _Redis extends \IPS\Data\Store
*/
protected static $cache = array();
/**
* @brief Already updated lastAccess?
*/
protected static $updatedLastAccess = FALSE;
/**
* Abstract Method: Get
*
* @param string $key
* @param string $key Key
* @return string|FALSE Value from the _datastore; FALSE if key doesn't exist
*/
public function get( $key )
@@ -77,11 +106,18 @@ class _Redis extends \IPS\Data\Store
try
{
/* Set the last access time */
if ( static::$updatedLastAccess === FALSE )
{
\IPS\Redis::i()->setex( 'redisStore_lastAccess', ( 3 * 3600 ), time() );
static::$updatedLastAccess = TRUE;
}
$return = \IPS\Redis::i()->get( $this->_getRedisKey() . '_' . $key );
if ( $return !== FALSE )
if ( $return !== FALSE AND $decoded = \IPS\Redis::i()->decode( $return ) )
{
static::$cache[ $key ] = \IPS\Redis::i()->decode( $return );
static::$cache[ $key ] = $decoded;
return static::$cache[ $key ];
}
else
@@ -152,7 +188,8 @@ class _Redis extends \IPS\Data\Store
{
try
{
return (bool) \IPS\Redis::i()->delete( $this->_getRedisKey() . '_' . $key );
unset( static::$cache[ $key ] );
return (bool) \IPS\Redis::i()->del( $this->_getRedisKey() . '_' . $key );
}
catch( \RedisException $e )
{
@@ -179,4 +216,15 @@ class _Redis extends \IPS\Data\Store
return FALSE;
}
}
/**
* Test the datastore engine to make sure it's working
* Overloaded here to ensure that if we're using a cluster, there isn't a false error because of the delay with RW
*
* @return bool
*/
public function test()
{
return \IPS\Redis::i()->test();
}
}