Php-redis Chinese Reference Manual _ Ping_echo_set_get_setex_psetex _...

Source: Internet
Author: User

Ping
Description
Check the current connection status

Check the status of the currently connected instance

Parameters
(None)

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

If a RedisException object in Throws fails, a connection error is returned.

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

Send a string to Redis and return the same string

Parameters
STRING: The message to send.

Return Value
STRING: the same message.

Get
Description
Get the value related to the specified key

Obtains the value associated with the specified key value.

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 related value or BOOL value. If the KEY does not exist, FALSE is returned. If there is a related KEY and value returned 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 lifecycle. The unit of the psetex () cycle 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 1 h 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 first checks whether the KEY exists in Redis. If it is not SET, False is returned.

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 an existing KEYS www.2cto.com

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

It can be an array of KEYS, an undefined numeric parameter, or a write KEY

Return value
Long Number of keys deleted.

Returns the number of KEY-VALUE deleted.

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: Si Yun Qilin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.