File tree Expand file tree Collapse file tree 3 files changed +54
-5
lines changed Expand file tree Collapse file tree 3 files changed +54
-5
lines changed Original file line number Diff line number Diff line change 16
16
*/
17
17
class Resque_Redis extends Redisent
18
18
{
19
+ /**
20
+ * Redis namespace
21
+ * @var string
22
+ */
23
+ private static $ defaultNamespace = 'resque: ' ;
19
24
/**
20
25
* @var array List of all commands in Redis that supply a key as their
21
26
* first argument. Used to prefix keys with the Resque namespace.
@@ -76,10 +81,22 @@ class Resque_Redis extends Redisent
76
81
// msetnx
77
82
// mset
78
83
// renamenx
79
-
84
+
85
+ /**
86
+ * Set Redis namespace (prefix) default: resque
87
+ * @param string $namespace
88
+ */
89
+ public static function prefix ($ namespace )
90
+ {
91
+ if (strpos ($ namespace , ': ' ) === false ) {
92
+ $ namespace .= ': ' ;
93
+ }
94
+ self ::$ defaultNamespace = $ namespace ;
95
+ }
96
+
80
97
/**
81
98
* Magic method to handle all function requests and prefix key based
82
- * operations with the 'resque:' key prefix.
99
+ * operations with the {self::$defaultNamespace} key prefix.
83
100
*
84
101
* @param string $name The name of the method called.
85
102
* @param array $args Array of supplied arguments to the method.
@@ -88,7 +105,7 @@ class Resque_Redis extends Redisent
88
105
public function __call ($ name , $ args ) {
89
106
$ args = func_get_args ();
90
107
if (in_array ($ name , $ this ->keyCommands )) {
91
- $ args [1 ][0 ] = ' resque: ' . $ args [1 ][0 ];
108
+ $ args [1 ][0 ] = self :: $ defaultNamespace . $ args [1 ][0 ];
92
109
}
93
110
try {
94
111
return parent ::__call ($ name , $ args [1 ]);
Original file line number Diff line number Diff line change 16
16
*/
17
17
class Resque_RedisCluster extends RedisentCluster
18
18
{
19
+ /**
20
+ * Redis namespace
21
+ * @var string
22
+ */
23
+ private static $ defaultNamespace = 'resque: ' ;
19
24
/**
20
25
* @var array List of all commands in Redis that supply a key as their
21
26
* first argument. Used to prefix keys with the Resque namespace.
@@ -76,10 +81,22 @@ class Resque_RedisCluster extends RedisentCluster
76
81
// msetnx
77
82
// mset
78
83
// renamenx
84
+
85
+ /**
86
+ * Set Redis namespace (prefix) default: resque
87
+ * @param string $namespace
88
+ */
89
+ public static function prefix ($ namespace )
90
+ {
91
+ if (strpos ($ namespace , ': ' ) === false ) {
92
+ $ namespace .= ': ' ;
93
+ }
94
+ self ::$ defaultNamespace = $ namespace ;
95
+ }
79
96
80
97
/**
81
98
* Magic method to handle all function requests and prefix key based
82
- * operations with the 'resque: ' key prefix.
99
+ * operations with the '{self::$defaultNamespace} ' key prefix.
83
100
*
84
101
* @param string $name The name of the method called.
85
102
* @param array $args Array of supplied arguments to the method.
@@ -88,7 +105,7 @@ class Resque_RedisCluster extends RedisentCluster
88
105
public function __call ($ name , $ args ) {
89
106
$ args = func_get_args ();
90
107
if (in_array ($ name , $ this ->keyCommands )) {
91
- $ args [1 ][0 ] = ' resque: ' . $ args [1 ][0 ];
108
+ $ args [1 ][0 ] = self :: $ defaultNamespace . $ args [1 ][0 ];
92
109
}
93
110
try {
94
111
return parent ::__call ($ name , $ args [1 ]);
Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ public function testRecreatedJobMatchesExistingJob()
100
100
$ this ->assertEquals ($ job ->payload ['args ' ], $ newJob ->getArguments ());
101
101
}
102
102
103
+
103
104
public function testFailedJobExceptionsAreCaught ()
104
105
{
105
106
$ payload = array (
@@ -166,4 +167,18 @@ public function testJobWithTearDownCallbackFiresTearDown()
166
167
167
168
$ this ->assertTrue (Test_Job_With_TearDown::$ called );
168
169
}
170
+
171
+ public function testJobWithNamespace ()
172
+ {
173
+ Resque_Redis::prefix ('php ' );
174
+ $ queue = 'jobs ' ;
175
+ $ payload = array ('another_value ' );
176
+ Resque::enqueue ($ queue , 'Test_Job_With_TearDown ' , $ payload );
177
+
178
+ $ this ->assertEquals (Resque::queues (), array ('jobs ' ));
179
+ $ this ->assertEquals (Resque::size ($ queue ), 1 );
180
+
181
+ Resque_Redis::prefix ('resque ' );
182
+ $ this ->assertEquals (Resque::size ($ queue ), 0 );
183
+ }
169
184
}
You can’t perform that action at this time.
0 commit comments