Skip to content

Commit

Permalink
Merge pull request #22 from clementtalleu/feat/add_install_doc
Browse files Browse the repository at this point in the history
remove expires + add doc
  • Loading branch information
clementtalleu authored Jun 9, 2024
2 parents d486c75 + 71006e1 commit 8cd427c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
10 changes: 9 additions & 1 deletion docs/advanced_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ $userRepository->findBy(['name' => 'John']); // Will retrieve all users with the
$userRepository->findBy(['name' => 'John'], ['age' => 'ASC']); // Will retrieve all users with the name 'John' sorted by age in ascending order
$userRepository->findBy(['name' => 'John'], ['age' => 'ASC'], 5); // Will retrieve 5 users with the name 'John' sorted by age in ascending order
$userRepository->count(['name' => 'John']); // Will retrieve an integer representing the number of users with the name 'John'
```
```

## Repository

You can create your own repository to query your objects in Redis. Then inject it in the
`#[RedisOm\Entity(repository: YourCustomRepository::class)]` attribute to use it.

Then in each custom repository you can add custom methods to query your objects in Redis.

34 changes: 34 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Installation

### PHP
To use the library you need a php-version >= 8.2 and the Redis extension installed.
If you don't have the Redis extension installed, you can use your favorite Redis client (for example Predis),
and create a new class that implements the `RedisClientInterface` interface, then inject it directly in the `#[RedisOm\Entity(client: YourRedisClient::class)]` attribute.


### Redis
You need a Redis server with a version >= 4.0. If you want to use the [JSON](https://redis.io/docs/latest/develop/data-types/json/) data type
you need a Redis server with the JSON module installed. By default, the library uses the HASH format type to store objects in Redis, which does not need any module.
But for indexing our objects and create the schema, you will need the [Redisearch](https://redis.io/search/) module installed.

We recommend using the [Redis stack](https://redis.io/about/about-stack/) to get all modules you need.

### Composer

Install the library by running the following command:

```console
composer require talleu/php-redis-om
```

Or add the library to your `composer.json` file:

```json
{
"require": {
"talleu/php-redis-om": "*"
}
}
```

Then run `composer update` to install the library.
11 changes: 10 additions & 1 deletion docs/mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Mapping object

You can customize the mapping configuration by adding parameters to you RedisOm\Entity attribute.
Customize the mapping configuration by adding parameters to you RedisOm\Entity attribute.

```php
<?php
Expand Down Expand Up @@ -70,6 +70,15 @@ Each of these parameters are optional and can be omitted. Here is a description
- Note: The redis client must implement the `RedisClientInterface` interface, it could be a php-redis client
or any other client that implements the interface.

You could alternate from JSON format to HASH format in each entity by setting the format parameter to `RedisFormat::HASH->value` or `RedisFormat::JSON->value`.
But be careful, if you switch the format in an entity that already has data stored in Redis, you will lose all the index stored in the previous format.

Dont forget to run the migration command after changing the format of an entity.

```console
vendor/bin/redisMigration <YOUR DIRECTORY PATH>
```


## Mapping properties
```php
Expand Down
1 change: 0 additions & 1 deletion src/Om/Mapping/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ final class Entity
{
public function __construct(
public ?string $prefix = null,
public ?int $expires = null,
public ?string $format = null,
public ?PersisterInterface $persister = null,
public ?ConverterInterface $converter = null,
Expand Down

0 comments on commit 8cd427c

Please sign in to comment.