forked from owncloud/core
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Patch] Unhardcoding access to redis memcache server
Unhardcoding access to memcache in order to use it outside EOS cache system.
- Loading branch information
nadir
committed
Apr 11, 2016
1 parent
6f9d689
commit b481f77
Showing
3 changed files
with
123 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
namespace OC\Files\ObjectStore; | ||
|
||
class Redis | ||
{ | ||
private static $redisInstance; | ||
|
||
private static function init() | ||
{ | ||
if(self::$redisInstance == null) | ||
{ | ||
self::$redisInstance = new \Redis(); | ||
|
||
if(!self::$redisInstance->connect('127.0.0.1', 6379)) | ||
{ | ||
\OCP\Util::writeLog('EOS MEMCACHE', 'Unable to connect to redis server on 127.0.0.1:6379', \OCP\Util::ERROR); | ||
self::$redisInstance = null; | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static function writeToCache($key, $value) | ||
{ | ||
if(self::init()) | ||
{ | ||
self::$redisInstance->set($key, $value); | ||
} | ||
else | ||
{ | ||
\OCP\Util::writeLog('REDIS MEMCACHE', 'Unable to access redis server', \OCP\Util::ERROR); | ||
} | ||
} | ||
|
||
public static function readFromCache($key) | ||
{ | ||
if(self::init()) | ||
{ | ||
self::$redisInstance->get($key); | ||
} | ||
else | ||
{ | ||
\OCP\Util::writeLog('REDIS MEMCACHE', 'Unable to access redis server', \OCP\Util::ERROR); | ||
} | ||
} | ||
|
||
public static function deleteFromCache($key) | ||
{ | ||
if(self::init()) | ||
{ | ||
self::$redisInstance->del($key); | ||
} | ||
else | ||
{ | ||
\OCP\Util::writeLog('REDIS MEMCACHE', 'Unable to access redis server', \OCP\Util::ERROR); | ||
} | ||
} | ||
|
||
public static function writeToCacheMap($hash, $key, $value) | ||
{ | ||
if(self::init()) | ||
{ | ||
self::$redisInstance->hSet($hash, $key, $value); | ||
} | ||
else | ||
{ | ||
\OCP\Util::writeLog('REDIS MEMCACHE', 'Unable to access redis server', \OCP\Util::ERROR); | ||
} | ||
} | ||
|
||
public static function readHashFromCacheMap($hash) | ||
{ | ||
if(self::init()) | ||
{ | ||
return self::$redisInstance->hGetALl($hash); | ||
} | ||
else | ||
{ | ||
\OCP\Util::writeLog('REDIS MEMCACHE', 'Unable to access memcache', \OCP\Util::ERROR); | ||
} | ||
} | ||
|
||
public static function readFromCacheMap($hash, $key) | ||
{ | ||
if(self::init()) | ||
{ | ||
return self::$redisInstance->hGet($hash, $key); | ||
} | ||
else | ||
{ | ||
\OCP\Util::writeLog('REDIS MEMCACHE', 'Unable to access memcache', \OCP\Util::ERROR); | ||
} | ||
} | ||
|
||
public static function deleteFromCacheMap($hash, $key) | ||
{ | ||
if(self::init()) | ||
{ | ||
self::$redisInstance->hDel($hash, $key); | ||
} | ||
else | ||
{ | ||
\OCP\Util::writeLog('REDIS MEMCACHE', 'Unable to access memcache', \OCP\Util::ERROR); | ||
} | ||
} | ||
} |