hSetNx

PHP Redis

hSetNx

Description

Adds a value to the hash stored at key only if this field isn't already in the hash.

添加一个VALUE到HASH STORE中,如果FIELD不存在。

Return value

BOOL TRUE if the field was set, FALSE if it was already present.

Example
$redis->delete('h')
$redis->hSetNx('h', 'key1', 'hello'); /* TRUE, 'key1' => 'hello' in the hash at "h" */
$redis->hSetNx('h', 'key1', 'world'); /* FALSE, 'key1' => 'hello' in the hash at "h". No change since the field wasn't replaced. */