php-redis中文帮助手册_系统相关_config_eval_evalSha_script...

config

Description

Get or Set the redis config keys.

取得或者设置REIDS系统配置KEYS。

Parameters

operation (string) either GET or SET
key string for SET, glob-pattern for GET. See http://redis.io/commands/config-get for examples.
value optional string (only for SET)

Return value

Associative array for GET, key -> value
bool for SET

Examples
$redis->config("GET", "*max-*-entries*");
$redis->config("SET", "dir", "/var/run/redis/dumps/");

eval

Description

Evaluate a LUA script serverside

在服务器端执行LUA脚本

Parameters

script string.
args array, optional.
num_keys int, optional.

Return value

Mixed. What is returned depends on what the LUA script itself returns, which could be a scalar value (int/string), or an array. Arrays that are returned can also contain other arrays, if that's how it was set up in your LUA script. If there is an error executing the LUA script, the getLastError() function can tell you the message that came back from Redis (e.g. compile error).

这个函数返回的结果是函数传输的LUA脚本的执行结果。结果可以是一个普通的数据类型,也可以使一个数组,数组内也可以嵌套数组。无论返回的结果是什么,都是取决于你的LUA脚本是如何执行的。如果你传输的LUA脚本存在错误,那么getLastError()能够返回出REDIS对于这个错误的具体消息。

Examples
$redis->eval("return 1"); // Returns an integer: 1
$redis->eval("return {1,2,3}"); // Returns Array(1,2,3)
$redis->del('mylist');
$redis->rpush('mylist','a');
$redis->rpush('mylist','b');
$redis->rpush('mylist','c');
// Nested response:  Array(1,2,3,Array('a','b','c'));
$redis->eval("return {1,2,3,redis.call('lrange','mylist',0,-1)}}");

evalSha

Description

Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself. In order to run this command Redis will have to have already loaded the script, either by running it or via the SCRIPT LOAD command.

Parameters

script_sha string. The sha1 encoded hash of the script you want to run.
args array, optional. Arguments to pass to the LUA script.
num_keys int, optional. The number of arguments that should go into the KEYS array, vs. the ARGV array when Redis spins the script

Return value

Mixed. See EVAL

Examples
$script = 'return 1';
$sha = $redis->script('load', $script);
$redis->evalSha($sha); // Returns 1

script

Description

Execute the Redis SCRIPT command to perform various operations on the scripting subsystem.

执行Redis脚本命令来执行各种操作。

Usage
$redis->script('load', $script);
$redis->script('flush');
$redis->script('kill');
$redis->script('exists', $script1, [$script2, $script3, ...]);
Return value
  • SCRIPT LOAD will return the SHA1 hash of the passed script on success, and FALSE on failure.
  • SCRIPT FLUSH should always return TRUE
  • SCRIPT KILL will return true if a script was able to be killed and false if not
  • SCRIPT EXISTS will return an array with TRUE or FALSE for each passed script

getLastError

Description

The last error message (if any) returned from a SCRIPT call

取得最后的错误消息。

Parameters

none

Return Value

A string with the last returned script based error message, or NULL if there is no error

Examples
$redis->eval('this-is-not-lua');
$err = $redis->getLastError(); 
// "ERR Error compiling script (new function): user_script:1: '=' expected near '-'"

_prefix

Description

A utility method to prefix the value with the prefix setting for phpredis.

用于给VALUE加入前缀

Parameters

value string. The value you wish to prefix

Return value

If a prefix is set up, the value now prefixed. If there is no prefix, the value will be returned unchanged.

Examples
$redis->setOpt(Redis::OPT_PREFIX, 'my-prefix:');
$redis->_prefix('my-value'); // Will return 'my-prefix:my-value'

_unserialize

Description

A utility method to unserialize data with whatever serializer is set up. If there is no serializer set, the value will be returned unchanged. If there is a serializer set up, and the data passed in is malformed, an exception will be thrown. This can be useful if phpredis is serializing values, and you return something from redis in a LUA script that is serialized.

反序列化函数,用于序列化的SET类型数据。如果参数不是序列化的SET,那么会直接返回。如果是一个序列化的SET,但不是PHP-REDIS序列化的格式,函数将抛出一个异常。

Parameters

value string. The value to be unserialized

Examples
$redis->setOpt(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$redis->_unserialize('a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}'); // Will return Array(1,2,3)

dump

Description

Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command. The data that comes out of DUMP is a binary representation of the key as Redis stores it.

把一个KEY从REIDS中销毁(但是这个销毁不是物理意义上销毁),这个被销毁的VALUE,可以使用RESTORE函数恢复出来。使用DUMP销毁的VALUE,函数将返回这个数据在REIDS中的二进制内存地址。

Parameters

key string

Return value

The Redis encoded value of the key, or FALSE if the key doesn't exist

Examples
$redis->set('foo', 'bar');
$val = $redis->dump('foo'); // $val will be the Redis encoded key value

restore

Description

Restore a key from the result of a DUMP operation.

恢复DUMP函数销毁的VALUE到一个新的KEY上。

Parameters

key string. The key name
ttl integer. How long the key should live (if zero, no expire will be set on the key)
value string (binary). The Redis encoded key value (from DUMP)

Examples
$redis->set('foo', 'bar');
$val = $redis->dump('foo');
$redis->restore('bar', 0, $val); // The key 'bar', will now be equal to the key 'foo'

migrate

Description

Migrates a key to a different Redis instance.

迁移一个KEY岛不同的REIDS实例。

Parameters

host string. The destination host
port integer. The TCP port to connect to.
key string. The key to migrate.
destination-db integer. The target DB.
timeout integer. The maximum amount of time given to this transfer.

Examples
$redis->migrate('backup', 6379, 'foo', 0, 3600);

time

Description

Return the current Redis server time.

返回当前REDIS服务器的生存时间。

Parameters

(none)

Return value

If successfull, the time will come back as an associative array with element zero being the unix timestamp, and element one being microseconds.

Examples
$redis->time();

你可能感兴趣的:(redis,PHP,phpredis,php-redis,中文帮助手册)