File tree 5 files changed +50
-3
lines changed
5 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,14 @@ application/config/config_auth.php # 登录及验证码配置
38
38
-----------------------------------------------
39
39
更新日志:
40
40
41
+ v0.3.6 (2015-12-11)
42
+
43
+ 增加对redis自带的auth身份验证的支持(详见application/config/config_redis.php)
44
+
45
+ 修改string类型的key的value时,可选择保持其原有生存期(ttl)不变
46
+
47
+ ——————————————————
48
+
41
49
v0.3.5 (2015-11-07)
42
50
43
51
修正了部分JS的错误
Original file line number Diff line number Diff line change 5
5
'name ' => 'localhost server ' ,
6
6
'host ' => '127.0.0.1 ' ,
7
7
'port ' => 6379 ,
8
+ 'auth ' => FALSE , //如无密码,可不设置此键,或将值设置为FALSE or NULL
8
9
),
9
10
/*
10
11
* 集群服务器
21
22
'127.0.0.1:7012',
22
23
),
23
24
),
24
- */
25
+ */
25
26
);
Original file line number Diff line number Diff line change @@ -97,10 +97,18 @@ private function _do_index()
97
97
98
98
if ( $ type == 'string ' ) {
99
99
//string
100
+ $ keep_ttl = get_post_arg ('keep_ttl ' , 0 , 'intval ' );
101
+ $ orig_ttl = 0 ;
102
+ if ( $ keep_ttl ) {
103
+ $ orig_ttl = (int )$ redis -> ttl ($ key );
104
+ }
100
105
$ result = $ redis -> set ($ key , $ value );
101
106
if ( ! $ result ) {
102
107
show_error ('操作失败 ' );
103
108
}
109
+ if ($ orig_ttl > 0 ) {
110
+ $ redis -> expire ($ key , $ orig_ttl );
111
+ }
104
112
} elseif ( $ type == 'hash ' ) {
105
113
//hash
106
114
$ hkey = get_post_arg ('hkey ' );
@@ -116,7 +124,7 @@ private function _do_index()
116
124
&& ( ! $ redis -> hExists ($ key , $ hkey ) )
117
125
){
118
126
//如果新的hkey不存在的话
119
- //删掉用来的旧KEY
127
+ //删掉原来的旧KEY
120
128
$ redis -> hDel ($ key , $ old_hkey );
121
129
}
122
130
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ class Redis_Model extends CI_Model {
7
7
private $ _host ;
8
8
private $ _port ;
9
9
private $ _db ;
10
+ private $ _auth ;
10
11
11
12
public function __construct ()
12
13
{
@@ -50,6 +51,10 @@ private function _init_cluster($redis_config)
50
51
} catch (Exception $ e ) {
51
52
show_error ('Can not connect to Redis Cluster. Message: ' . $ e -> getMessage ());
52
53
}
54
+
55
+ if ( ! $ this -> auth () ) {
56
+ show_error ('Redis Server ( ' . $ this -> _host . ': ' . $ this -> _port . ') 认证密码错误! ' );
57
+ }
53
58
}
54
59
55
60
@@ -60,6 +65,7 @@ private function _init_redis($redis_config)
60
65
$ this -> _host = $ redis_config ['host ' ];
61
66
$ this -> _port = isset ($ redis_config ['port ' ]) ? $ redis_config ['port ' ] : 6379 ;
62
67
$ this -> _db = isset ($ redis_config ['db ' ]) ? $ redis_config ['db ' ] : 0 ;
68
+ $ this -> _auth = isset ($ redis_config ['auth ' ]) ? $ redis_config ['auth ' ] : FALSE ;
63
69
64
70
65
71
$ this -> _redis = new Redis ();
@@ -101,9 +107,25 @@ public function select_db($db)
101
107
{
102
108
$ db = (int )$ db ;
103
109
$ this -> _db = $ db ;
104
- $ this -> _redis -> select ($ this -> _db );
110
+ try {
111
+ $ this -> _redis -> select ($ this -> _db );
112
+ } catch (Exception $ e ) {
113
+ show_error ('连接服务器时发生错误: ' . $ e -> getMessage ());
114
+ }
105
115
}
106
116
117
+ /**
118
+ * 设置认证密码
119
+ */
120
+ public function auth ()
121
+ {
122
+ if ( ( FALSE !== $ this -> _auth )
123
+ && ( NULL !== $ this -> _auth )
124
+ ){
125
+ return $ this -> _redis -> auth ($ this -> _auth );
126
+ }
127
+ return TRUE ;
128
+ }
107
129
108
130
/**
109
131
*
Original file line number Diff line number Diff line change 35
35
<textarea name="value" id="value" cols="80" rows="20"><?= nl2br (format_html ($ value ))?> </textarea>
36
36
</p>
37
37
<input type="hidden" name="oldvalue" value="<?= format_html ($ value )?> ">
38
+ <?php
39
+ if ( ($ type == 'string ' ) && ($ is_edit ) ) {
40
+ ?>
41
+ <p><input type="checkbox" name="keep_ttl" value="1" checked>保持生存期(ttl)不变</p>
42
+ <?php
43
+ }
44
+ ?>
38
45
<p>
46
+
39
47
<input type="submit" class="button" value="<?= $ is_edit ? '编辑 ' : '新增 ' ?> ">
40
48
</p>
41
49
</form>
You can’t perform that action at this time.
0 commit comments