Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
cacheengineredis.php
1<?php
2namespace Bitrix\Main\Data;
3
5{
6 public function getConnectionName() : string
7 {
8 return 'cache.redis';
9 }
10
11 public static function getConnectionClass()
12 {
13 return RedisConnection::class;
14 }
15
16 public function set($key, $ttl, $value) : bool
17 {
18 $ttl = (int) $ttl;
19 if ($ttl > 0)
20 {
21 return self::$engine->setex($key, $ttl, $value);
22 }
23 else
24 {
25 return self::$engine->set($key, $value);
26 }
27 }
28
29 public function get($key)
30 {
31 return self::$engine->get($key);
32 }
33
34 public function del($key)
35 {
36 self::$engine->del($key);
37 }
38
39 public function setNotExists($key, $ttl, $value)
40 {
41 $ttl = (int) $ttl;
42 if (self::$engine->setnx($key, $value))
43 {
44 if ($ttl > 0)
45 {
46 self::$engine->expire($key, $ttl);
47 }
48
49 return true;
50 }
51
52 return false;
53 }
54
55 public function addToSet($key, $value)
56 {
57 self::$engine->sAdd($key, $value);
58 }
59
60 public function getSet($key) : array
61 {
62 $list = self::$engine->sMembers($key);
63 if (!is_array($list))
64 {
65 $list = [];
66 }
67 return $list;
68 }
69
70 public function deleteBySet($key, $prefix = '')
71 {
72 $list = self::$engine->sMembers($key);
73
74 if (is_array($list) && !empty($list))
75 {
76 if ($prefix == '')
77 {
78 self::$engine->del($list);
79 }
80 else
81 {
82 foreach ($list as $key)
83 {
84 self::$engine->del($prefix . $key);
85 }
86 }
87 }
88 }
89
90 public function delFromSet($key, $member)
91 {
92 if (is_array($member))
93 {
94 foreach ($member as $keyID)
95 {
96 self::$engine->sRem($key, $keyID);
97 }
98 }
99 else
100 {
101 self::$engine->sRem($key, $member);
102 }
103 }
104}