Jamm\Memory\RedisObject::add PHP Метод

add() публичный Метод

Add value to the memory storage, only if this key does not exists (or false will be returned).
public add ( string $key, mixed $value, integer $ttl = 259200, array | string $tags = NULL ) : boolean
$key string
$value mixed
$ttl integer
$tags array | string
Результат boolean
    public function add($key, $value, $ttl = 259200, $tags = NULL)
    {
        $redis_key = $this->prefix . $key;
        $ttl = intval($ttl);
        if (!is_scalar($value)) {
            $set = $this->redis->SetNX($redis_key, serialize($value));
            if (!$set) {
                return false;
            }
            $this->setKeySerialization(true, $key, $ttl);
        } else {
            $set = $this->redis->SetNX($redis_key, $value);
            if (!$set) {
                return false;
            }
            $this->setKeySerialization(false, $key, $ttl);
        }
        if ($ttl > 0) {
            $this->redis->Expire($redis_key, $ttl);
        }
        if (!empty($tags)) {
            $this->setTags($key, $tags);
        }
        return true;
    }