Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
integration
prechecker
Commits
7782e661
Unverified
Commit
7782e661
authored
Mar 19, 2017
by
Mike Olsen
Committed by
Skylar Kelty
Mar 27, 2017
Browse files
MDL-58311 cache: Add password support for redis
add password support for redis connects in cache and session
parent
98c4094e
Changes
7
Show whitespace changes
Inline
Side-by-side
cache/stores/redis/addinstanceform.php
View file @
7782e661
...
...
@@ -44,6 +44,10 @@ class cachestore_redis_addinstance_form extends cachestore_addinstance_form {
$form
->
addHelpButton
(
'server'
,
'server'
,
'cachestore_redis'
);
$form
->
addRule
(
'server'
,
get_string
(
'required'
),
'required'
);
$form
->
addElement
(
'passwordunmask'
,
'password'
,
get_string
(
'password'
,
'cachestore_redis'
));
$form
->
setType
(
'password'
,
PARAM_RAW
);
$form
->
addHelpButton
(
'password'
,
'password'
,
'cachestore_redis'
);
$form
->
addElement
(
'text'
,
'prefix'
,
get_string
(
'prefix'
,
'cachestore_redis'
),
array
(
'size'
=>
16
));
$form
->
setType
(
'prefix'
,
PARAM_TEXT
);
// We set to text but we have a rule to limit to alphanumext.
$form
->
addHelpButton
(
'prefix'
,
'prefix'
,
'cachestore_redis'
);
...
...
cache/stores/redis/lang/en/cachestore_redis.php
View file @
7782e661
...
...
@@ -34,8 +34,12 @@ $string['serializer_igbinary'] = 'The igbinary serializer.';
$string
[
'serializer_php'
]
=
'The default PHP serializer.'
;
$string
[
'server'
]
=
'Server'
;
$string
[
'server_help'
]
=
'This sets the hostname or IP address of the Redis server to use.'
;
$string
[
'password'
]
=
'Password'
;
$string
[
'password_help'
]
=
'This sets the password of the Redis server.'
;
$string
[
'test_server'
]
=
'Test server'
;
$string
[
'test_server_desc'
]
=
'Redis server to use for testing.'
;
$string
[
'test_password'
]
=
'Test server password'
;
$string
[
'test_password_desc'
]
=
'Redis test server password.'
;
$string
[
'test_serializer'
]
=
'Serializer'
;
$string
[
'test_serializer_desc'
]
=
'Serializer to use for testing.'
;
$string
[
'useserializer'
]
=
'Use serializer'
;
...
...
cache/stores/redis/lib.php
View file @
7782e661
...
...
@@ -134,8 +134,9 @@ class cachestore_redis extends cache_store implements cache_is_key_aware, cache_
if
(
array_key_exists
(
'serializer'
,
$configuration
))
{
$this
->
serializer
=
(
int
)
$configuration
[
'serializer'
];
}
$password
=
!
empty
(
$configuration
[
'password'
])
?
$configuration
[
'password'
]
:
''
;
$prefix
=
!
empty
(
$configuration
[
'prefix'
])
?
$configuration
[
'prefix'
]
:
''
;
$this
->
redis
=
$this
->
new_redis
(
$configuration
[
'server'
],
$prefix
);
$this
->
redis
=
$this
->
new_redis
(
$configuration
[
'server'
],
$prefix
,
$password
);
}
/**
...
...
@@ -144,9 +145,10 @@ class cachestore_redis extends cache_store implements cache_is_key_aware, cache_
*
* @param string $server The server connection string
* @param string $prefix The key prefix
* @param string $password The server connection password
* @return Redis
*/
protected
function
new_redis
(
$server
,
$prefix
=
''
)
{
protected
function
new_redis
(
$server
,
$prefix
=
''
,
$password
=
''
)
{
$redis
=
new
Redis
();
$port
=
null
;
if
(
strpos
(
$server
,
':'
))
{
...
...
@@ -155,6 +157,9 @@ class cachestore_redis extends cache_store implements cache_is_key_aware, cache_
$port
=
$serverconf
[
1
];
}
if
(
$redis
->
connect
(
$server
,
$port
))
{
if
(
!
empty
(
$password
))
{
$redis
->
auth
(
$password
);
}
$redis
->
setOption
(
Redis
::
OPT_SERIALIZER
,
$this
->
serializer
);
if
(
!
empty
(
$prefix
))
{
$redis
->
setOption
(
Redis
::
OPT_PREFIX
,
$prefix
);
...
...
cache/stores/redis/settings.php
View file @
7782e661
...
...
@@ -34,6 +34,14 @@ $settings->add(
16
)
);
$settings
->
add
(
new
admin_setting_configpasswordunmask
(
'cachestore_redis/test_password'
,
get_string
(
'test_password'
,
'cachestore_redis'
),
get_string
(
'test_password_desc'
,
'cachestore_redis'
),
''
)
);
if
(
class_exists
(
'Redis'
))
{
// Only if Redis is available.
...
...
cache/stores/redis/version.php
View file @
7782e661
...
...
@@ -24,7 +24,7 @@
defined
(
'MOODLE_INTERNAL'
)
||
die
();
$plugin
->
version
=
201
61205
00
;
$plugin
->
version
=
201
70319
00
;
$plugin
->
requires
=
2016112900
;
// Requires this Moodle version (3.0.4).
$plugin
->
maturity
=
MATURITY_STABLE
;
$plugin
->
component
=
'cachestore_redis'
;
...
...
config-dist.php
View file @
7782e661
...
...
@@ -265,6 +265,7 @@ $CFG->admin = 'admin';
// $CFG->session_redis_host = '127.0.0.1';
// $CFG->session_redis_port = 6379; // Optional.
// $CFG->session_redis_database = 0; // Optional, default is db 0.
// $CFG->session_redis_auth = ''; // Optional, default is don't set one.
// $CFG->session_redis_prefix = ''; // Optional, default is don't set one.
// $CFG->session_redis_acquire_lock_timeout = 120;
// $CFG->session_redis_lock_expire = 7200;
...
...
lib/classes/session/redis.php
View file @
7782e661
...
...
@@ -44,6 +44,8 @@ class redis extends handler {
protected
$host
=
''
;
/** @var int $port The port to connect to */
protected
$port
=
6379
;
/** @var string $auth redis password */
protected
$auth
=
''
;
/** @var int $database the Redis database to store sesions in */
protected
$database
=
0
;
/** @var array $servers list of servers parsed from save_path */
...
...
@@ -81,6 +83,10 @@ class redis extends handler {
$this
->
port
=
(
int
)
$CFG
->
session_redis_port
;
}
if
(
isset
(
$CFG
->
session_redis_auth
))
{
$this
->
auth
=
$CFG
->
session_redis_auth
;
}
if
(
isset
(
$CFG
->
session_redis_database
))
{
$this
->
database
=
(
int
)
$CFG
->
session_redis_database
;
}
...
...
@@ -156,6 +162,13 @@ class redis extends handler {
if
(
!
$this
->
connection
->
connect
(
$this
->
host
,
$this
->
port
,
1
))
{
throw
new
RedisException
(
'Unable to connect to host.'
);
}
if
(
$this
->
auth
!==
''
)
{
if
(
!
$this
->
connection
->
auth
(
$this
->
auth
))
{
throw
new
RedisException
(
'Unable to authenticate.'
);
}
}
if
(
!
$this
->
connection
->
setOption
(
\
Redis
::
OPT_SERIALIZER
,
$this
->
serializer
))
{
throw
new
RedisException
(
'Unable to set Redis PHP Serializer option.'
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment