You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's an update on the README to make the usage examples clearer:
I've updated the README.md to provide more distinct and clearer examples for initializing the DBAL adapter:
- I clarified basic usage without Redis, showcasing backward compatibility by omitting Redis configuration.
- I improved the section on Redis caching usage, ensuring the example for initialization with Redis is clear.
- I renamed sections for better discoverability of these usage patterns.
Copy file name to clipboardExpand all lines: README.md
+43-21Lines changed: 43 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,28 +26,45 @@ Via [Composer](https://getcomposer.org/).
26
26
composer require casbin/dbal-adapter
27
27
```
28
28
29
-
### Usage
29
+
### Basic Usage (Without Redis Caching)
30
30
31
-
```php
31
+
This section describes how to use the adapter with a direct database connection, without leveraging Redis for caching.
32
+
33
+
You can initialize the adapter by passing either a Doctrine DBAL connection parameter array or an existing `Doctrine\DBAL\Connection` instance to the `Adapter::newAdapter()` method or the `Adapter` constructor.
32
34
35
+
**Example:**
36
+
37
+
```php
33
38
require_once './vendor/autoload.php';
34
39
35
40
use Casbin\Enforcer;
36
41
use CasbinAdapter\DBAL\Adapter as DatabaseAdapter;
42
+
use Doctrine\DBAL\DriverManager; // Required if creating a new connection object
37
43
38
-
$config = [
39
-
// Either 'driver' with one of the following values:
To improve performance and reduce database load, the adapter supports caching policy data using [Redis](https://redis.io/). When enabled, Casbin policies will be fetched from Redis if available, falling back to the database if the cache is empty.
68
85
69
-
#### Configuration
70
-
71
-
To enable Redis caching, pass a Redis configuration array as the second argument to the `Adapter::newAdapter()` method or the `Adapter` constructor.
86
+
To enable Redis caching, provide a Redis configuration array as the second argument when initializing the adapter. The first argument remains your Doctrine DBAL connection (either a parameters array or a `Connection` object).
72
87
73
-
Available Redis configuration options:
88
+
**Redis Configuration Options:**
74
89
75
90
*`host` (string): Hostname or IP address of the Redis server. Default: `'127.0.0.1'`.
76
91
*`port` (int): Port number of the Redis server. Default: `6379`.
0 commit comments