Home > Backend Development > PHP Tutorial > php-redis Chinese reference manual_Ping_echo_set_get_setex_psetex_..._PHP tutorial

php-redis Chinese reference manual_Ping_echo_set_get_setex_psetex_..._PHP tutorial

WBOY
Release: 2016-07-13 17:52:45
Original
1385 people have browsed it

ping
Description
Check the current connection status

Check the status of the current connection instance

Parameters
(none)

Return Value
STRING: +PONG on success. Throws a RedisException object on connectivity error, as described above.

If it fails, Throws a RedisException object to report a connection error.

echo
Description
Sends a string to Redis, which replies with the same string

Send a string to Redis and return an identical string

Parameters
STRING: The message to send.

Return Value
STRING: the same message.

get
Description
Get the value related to the specified key

Get the value associated with the specified key

Parameters
key

Return Value
String or Bool: If key didn't exist, FALSE is returned. Otherwise, the value related to this key is returned.

Returns the relevant value or BOOL value. If KEY does not exist, returns FALSE. If there is a relevant KEY and value return the value.

Examples
$redis->get('key');
set
Description
Set the string value in argument as value of the key.

Set value to KEY

Parameters
Key
Value
Timeout (optional). Calling SETEX is preferred if you want a timeout.

Return value
Bool TRUE if the command is successful.

Examples
$redis->set('key', 'value');
setex, psetex
Description
Set the string value in argument as value of the key, with a time to live. PSETEX uses a TTL in milliseconds.

Set a KEY-VALUE with a life cycle. The period unit used by psetex() is milliseconds.

Parameters
Key TTL Value

Return value
Bool TRUE if the command is successful.

Examples
$redis->setex('key', 3600, 'value'); // sets key → value, with 1h TTL.
$redis->psetex('key', 100, 'value'); // sets key → value, with 0.1 sec TTL.
setnx
Description
Set the string value in argument as value of the key if the key doesn't already exist in the database.

setnx is used to set a KEY-VALUE. This function will first determine whether there is this KEY in Redis. If not, SET will be used. If there is, it will return False.

Parameters
key value

Return value
Bool TRUE in case of success, FALSE in case of failure.

Examples
$redis->setnx('key', 'value'); /* return TRUE */
$redis->setnx('key', 'value'); /* return FALSE */
del, delete
Description
Remove specified keys.

Remove existing KEYS www.2cto.com

Parameters
An array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN

can be an array of KEYS, or an undefined numeric parameter, or write KEY one by one

Return value
Long Number of keys deleted.

Returns the number of deleted KEY-VALUE

Examples
$redis->set('key1', 'val1');
$redis->set('key2', 'val2');
$redis->set('key3', 'val3');
$redis->set('key4', 'val4');

$redis->delete('key1', 'key2'); /* return 2 */
$redis->delete(array('key3', 'key4')); /* return 2 */


Author: Siyun Qilin

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478095.htmlTechArticleping Description Check the current connection status Check the status of the current connection instance Parameters (none) Return Value STRING: +PONG on success. Throws a RedisException object on co...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template