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

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

Save variable in memory storage
public save ( string $key, mixed $value, integer $ttl = 259200, array | string $tags = NULL ) : boolean
$key string - key
$value mixed - value
$ttl integer - time to live (store) in seconds
$tags array | string - array of tags for this key
Результат boolean
    public function save($key, $value, $ttl = 259200, $tags = NULL)
    {
        $ttl = intval($ttl);
        if ($ttl > 0) {
            if (is_scalar($value)) {
                $set = $this->redis->SetEX($this->prefix . $key, $ttl, $value);
                $this->setKeySerialization(false, $key, $ttl);
            } else {
                $set = $this->redis->SetEX($this->prefix . $key, $ttl, serialize($value));
                $this->setKeySerialization(true, $key, $ttl);
            }
        } else {
            if (is_scalar($value)) {
                $set = $this->redis->Set($this->prefix . $key, $value);
                $this->setKeySerialization(false, $key, 0);
            } else {
                $set = $this->redis->Set($this->prefix . $key, serialize($value));
                $this->setKeySerialization(true, $key, $ttl);
            }
        }
        if (!$set) {
            return false;
        }
        if (!empty($tags)) {
            $this->setTags($key, $tags);
        }
        return true;
    }