TheWebGuy
TheWebGuy

Reputation: 12525

Redis Cache Server - Multiple Website Ennvironments

I am new to redis but I installed a windows version today. I was able to use the StackExchange.Redis c# client (https://github.com/StackExchange/StackExchange.Redis)

But now I have a slight problem. I have one site with multiple environments that use the same redis server, so I am running into a key collision issue.

What's the best way to support a multiple environment app on one redis server. I read about Database Index, but it seems thats frowned upon based on my research on some dated articles. In 2016, whats the recommended approach?

Upvotes: 1

Views: 1050

Answers (1)

for_stack
for_stack

Reputation: 22886

Normally, there're 2 solutions:

Assign an exclusive database for each app

Just as you mentioned, you can store data into an exclusive database for different apps. With the select command, you can switch between these databases.

Each app has different key prefix

If you want/have to store all data in a single database, you can use the key prefix to avoid key collision. For example: keys for app1 has a prefix: app1, and keys for app2 has a different prefix: app2.

// set keys for app1
set app1:key1 value
set app1:key2 value
// ...
// set keys for app2
set app2:key1 value
set app2:key2 value

Upvotes: 2

Related Questions