Skip to content

Commit 522f301

Browse files
committed
Add new commands: eval(), evalSha(), script(), getLastError(), _prefix(), _unserialize(), dump(), restore(), migrate(), time()
1 parent 3aa107d commit 522f301

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

redisphp.php

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@
55
* @link https://github.com/ukko/phpredis-phpdoc
66
*
77
* @method echo string $string Sends a string to Redis, which replies with the same string
8+
*
9+
* @method eval( $script, $args = array(), $numKeys = 0 )
10+
* Evaluate a LUA script serverside
11+
* @param string $script
12+
* @param array $args
13+
* @param int $numKeys
14+
* @return Mixed. What is returned depends on what the LUA script itself returns, which could be a scalar value
15+
* (int/string), or an array. Arrays that are returned can also contain other arrays, if that's how it was set up in
16+
* your LUA script. If there is an error executing the LUA script, the getLastError() function can tell you the
17+
* message that came back from Redis (e.g. compile error).
18+
* @link http://redis.io/commands/eval
19+
* @example
20+
* <pre>
21+
* $redis->eval("return 1"); // Returns an integer: 1
22+
* $redis->eval("return {1,2,3}"); // Returns Array(1,2,3)
23+
* $redis->del('mylist');
24+
* $redis->rpush('mylist','a');
25+
* $redis->rpush('mylist','b');
26+
* $redis->rpush('mylist','c');
27+
* // Nested response: Array(1,2,3,Array('a','b','c'));
28+
* $redis->eval("return {1,2,3,redis.call('lrange','mylist',0,-1)}}");
29+
* </pre>
30+
*
831
*/
932
class Redis
1033
{
@@ -2706,6 +2729,152 @@ public function hMGet( $key, $hashKeys ) {}
27062729
* </pre>
27072730
*/
27082731
public function config( $operation, $key, $value ) {}
2732+
2733+
/**
2734+
* Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself.
2735+
* In order to run this command Redis will have to have already loaded the script, either by running it or via
2736+
* the SCRIPT LOAD command.
2737+
* @param string $scriptSha
2738+
* @param array $args
2739+
* @param int $numKeys
2740+
* @return mixed. @see eval()
2741+
* @see eval()
2742+
* @link http://redis.io/commands/evalsha
2743+
* @example
2744+
* <pre>
2745+
* $script = 'return 1';
2746+
* $sha = $redis->script('load', $script);
2747+
* $redis->evalSha($sha); // Returns 1
2748+
* </pre>
2749+
*/
2750+
public function evalSha( $scriptSha, $args = array(), $numKeys = 0 ) {}
2751+
2752+
/**
2753+
* Execute the Redis SCRIPT command to perform various operations on the scripting subsystem.
2754+
* @param string $command load | flush | kill | exists
2755+
* @param string $script
2756+
* @return mixed
2757+
* @link http://redis.io/commands/script-load
2758+
* @link http://redis.io/commands/script-kill
2759+
* @link http://redis.io/commands/script-flush
2760+
* @link http://redis.io/commands/script-exists
2761+
* @example
2762+
* <pre>
2763+
* $redis->script('load', $script);
2764+
* $redis->script('flush');
2765+
* $redis->script('kill');
2766+
* $redis->script('exists', $script1, [$script2, $script3, ...]);
2767+
* </pre>
2768+
*
2769+
* SCRIPT LOAD will return the SHA1 hash of the passed script on success, and FALSE on failure.
2770+
* SCRIPT FLUSH should always return TRUE
2771+
* SCRIPT KILL will return true if a script was able to be killed and false if not
2772+
* SCRIPT EXISTS will return an array with TRUE or FALSE for each passed script
2773+
*/
2774+
public function script( $command, $script ) {}
2775+
2776+
/**
2777+
* The last error message (if any) returned from a SCRIPT call
2778+
* @return string A string with the last returned script based error message, or NULL if there is no error
2779+
* @example
2780+
* <pre>
2781+
* $redis->eval('this-is-not-lua');
2782+
* $err = $redis->getLastError();
2783+
* // "ERR Error compiling script (new function): user_script:1: '=' expected near '-'"
2784+
* </pre>
2785+
*/
2786+
public function getLastError() {}
2787+
2788+
/**
2789+
* A utility method to prefix the value with the prefix setting for phpredis.
2790+
* @param $value The value you wish to prefix
2791+
* @return string If a prefix is set up, the value now prefixed. If there is no prefix, the value will be returned unchanged.
2792+
* @example
2793+
* <pre>
2794+
* $redis->setOpt(Redis::OPT_PREFIX, 'my-prefix:');
2795+
* $redis->_prefix('my-value'); // Will return 'my-prefix:my-value'
2796+
* </pre>
2797+
*/
2798+
public function _prefix( $value ) {}
2799+
2800+
/**
2801+
* A utility method to unserialize data with whatever serializer is set up. If there is no serializer set, the
2802+
* value will be returned unchanged. If there is a serializer set up, and the data passed in is malformed, an
2803+
* exception will be thrown. This can be useful if phpredis is serializing values, and you return something from
2804+
* redis in a LUA script that is serialized.
2805+
* @param string $value The value to be unserialized
2806+
* @return mixed
2807+
* @example
2808+
* <pre>
2809+
* $redis->setOpt(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
2810+
* $redis->_unserialize('a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}'); // Will return Array(1,2,3)
2811+
* </pre>
2812+
*/
2813+
public function _unserialize( $value ) {}
2814+
2815+
/**
2816+
* Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command.
2817+
* The data that comes out of DUMP is a binary representation of the key as Redis stores it.
2818+
* @param string $key
2819+
* @return string The Redis encoded value of the key, or FALSE if the key doesn't exist
2820+
* @link http://redis.io/commands/dump
2821+
* @example
2822+
* <pre>
2823+
* $redis->set('foo', 'bar');
2824+
* $val = $redis->dump('foo'); // $val will be the Redis encoded key value
2825+
* </pre>
2826+
*/
2827+
public function dump( $key ) {}
2828+
2829+
/**
2830+
* Restore a key from the result of a DUMP operation.
2831+
*
2832+
* @param string $key The key name
2833+
* @param int $ttl How long the key should live (if zero, no expire will be set on the key)
2834+
* @param string $value (binary). The Redis encoded key value (from DUMP)
2835+
* @return bool
2836+
* @link http://redis.io/commands/restore
2837+
* @example
2838+
* <pre>
2839+
* $redis->set('foo', 'bar');
2840+
* $val = $redis->dump('foo');
2841+
* $redis->restore('bar', 0, $val); // The key 'bar', will now be equal to the key 'foo'
2842+
* </pre>
2843+
*/
2844+
public function restore( $key, $ttl, $value ) {}
2845+
2846+
/**
2847+
* Migrates a key to a different Redis instance.
2848+
*
2849+
* @param string $host The destination host
2850+
* @param int $port The TCP port to connect to.
2851+
* @param string $key The key to migrate.
2852+
* @param int $db The target DB.
2853+
* @param int $timeout The maximum amount of time given to this transfer.
2854+
* @return bool
2855+
* @link http://redis.io/commands/migrate
2856+
* @example
2857+
* <pre>
2858+
* $redis->migrate('backup', 6379, 'foo', 0, 3600);
2859+
* </pre>
2860+
*/
2861+
public function migrate( $host, $port, $key, $db, $timeout ) {}
2862+
2863+
/**
2864+
* Return the current Redis server time.
2865+
* @return array If successfull, the time will come back as an associative array with element zero being the
2866+
* unix timestamp, and element one being microseconds.
2867+
* @link http://redis.io/commands/time
2868+
* @example
2869+
* <pre>
2870+
* var_dump( $redis->time() );
2871+
* // array(2) {
2872+
* // [0] => string(10) "1342364352"
2873+
* // [1] => string(6) "253002"
2874+
* // }
2875+
* </pre>
2876+
*/
2877+
public function time() {}
27092878
}
27102879

27112880
class RedisException extends Exception {}

0 commit comments

Comments
 (0)