Predis (opens new window) integration into Nette/DI (opens new window)

# Content

# Setup

composer require contributte/redis
1
extensions:
	redis: Contributte\Redis\DI\RedisExtension
1
2

# Configuration

redis:
	# Setup Tracy panel
	debug: %debugMode%

	connection:
		default:
			uri: tcp://127.0.0.1:6379

			# Options passed directly to Predis\Client
			# https://github.com/nrk/predis#client-configuration
			options: []
1
2
3
4
5
6
7
8
9
10
11

# Sessions

Setup Nette\Http\Session to store session with Redis

redis:
	connection:
		default:
			sessions: true

			## you can also configure session
			sessions:
				ttl: 3600 # time in seconds after which is session invalidated
1
2
3
4
5
6
7
8

# Cache

Replaces Nette\Caching\IStorage in DIC with RedisStorage

redis:
	connection:
		default:
			storage: false
1
2
3
4

# Sessions and cache

When using sessions and cache make sure you use 2 different databases. One for cache and one for sessions. In case you will use only 1 database for both you will loose sessions when clearing cache. This would be preferred config:

connection:
	default:
		uri: tcp://127.0.0.1:6379
		sessions: false
		storage: true
		options: ['parameters': ['database': 0]]
	session:
		uri: tcp://127.0.0.1:6379
		sessions: true
		storage: false
		options: ['parameters': ['database': 1]]
1
2
3
4
5
6
7
8
9
10
11