{"size": 584, "ext": "js", "max_stars_repo_path": "src/infrastructure/imagerepository.js", "max_stars_repo_name": "adhefer/pizzashop-genspain-images", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/infrastructure/imagerepository.js", "max_issues_repo_name": "adhefer/pizzashop-genspain-images", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/infrastructure/imagerepository.js", "max_forks_repo_name": "adhefer/pizzashop-genspain-images", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.1379310345, "max_line_length": 73, "alphanum_fraction": 0.6489726027}
import Redis from "ioredis";
import {Image} from "../domain/image.js";
const oneDayInSeconds = 24 * 60 * 60;


export class ImageRepository {
  constructor() {
    this._redis = new Redis();
  }

  async add(image) {
    await this._redis.set(image.id, image.buffer, "EX", oneDayInSeconds);
  }

  async get(id) {
    const buffer = await this._redis.getBuffer(id);
    const img = Object.create(Image.prototype)
    return Object.assign(img, {id, buffer})
  }

  async remove(image) {
    await this._redis.del(image.id);
  }

  async dispose() {
    await this._redis.quit();
  }
}
