|
|
@@ -17,13 +17,17 @@ class RedisService extends BaseRedis
|
|
|
*/
|
|
|
public static function set($key, $data, $expire =null)
|
|
|
{
|
|
|
- $expire = $expire !=null ? $expire : env('REDIS_EXPIRE', 24 * 3600);
|
|
|
- $data = is_array($data) && !empty($data)? json_encode($data, 256) : $data;
|
|
|
- $data = !empty($data)? $data : null;
|
|
|
- if ($expire > 0) {
|
|
|
- return BaseRedis::setex($key, $expire, $data);
|
|
|
- } else {
|
|
|
- return BaseRedis::set($key, $data);
|
|
|
+ try{
|
|
|
+ $expire = $expire !=null ? $expire : env('REDIS_EXPIRE', 24 * 3600);
|
|
|
+ $data = is_array($data) && !empty($data)? json_encode($data, 256) : $data;
|
|
|
+ $data = !empty($data)? $data : null;
|
|
|
+ if ($expire > 0) {
|
|
|
+ return BaseRedis::setex($key, $expire, $data);
|
|
|
+ } else {
|
|
|
+ return BaseRedis::set($key, $data);
|
|
|
+ }
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -34,9 +38,13 @@ class RedisService extends BaseRedis
|
|
|
*/
|
|
|
public static function get($key)
|
|
|
{
|
|
|
- $data = BaseRedis::get($key);
|
|
|
- $jsonData = $data ? json_decode($data, true) : [];
|
|
|
- return $jsonData ? $jsonData : $data;
|
|
|
+ try {
|
|
|
+ $data = BaseRedis::get($key);
|
|
|
+ $jsonData = $data ? json_decode($data, true) : [];
|
|
|
+ return $jsonData ? $jsonData : $data;
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -103,7 +111,11 @@ class RedisService extends BaseRedis
|
|
|
*/
|
|
|
public static function clear($key)
|
|
|
{
|
|
|
- return BaseRedis::del($key);
|
|
|
+ try{
|
|
|
+ return BaseRedis::del($key);
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -112,12 +124,16 @@ class RedisService extends BaseRedis
|
|
|
* @return bool
|
|
|
*/
|
|
|
public static function keyDel($key){
|
|
|
- $keys = BaseRedis::keys($key);
|
|
|
- foreach($keys as $key){
|
|
|
- BaseRedis::del($key);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ $keys = BaseRedis::keys($key);
|
|
|
+ foreach($keys as $key){
|
|
|
+ BaseRedis::del($key);
|
|
|
+ }
|
|
|
|
|
|
- return true;
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $exception){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|