Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/apis/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Redis comes with a wide range of commands that help you to develop real-time app

As a developer, you will likely use one of our supported client libraries for connecting and executing commands.

- [Connect with Redis clients introduction]({{< relref "/develop/connect/clients/" >}})
- [Connect with Redis clients introduction]({{< relref "/develop/clients" >}})

### Programmability APIs

Expand Down
2 changes: 1 addition & 1 deletion content/commands/client-caching/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ title: CLIENT CACHING
This command controls the tracking of the keys in the next command executed
by the connection, when tracking is enabled in `OPTIN` or `OPTOUT` mode.
Please check the
[client side caching documentation]({{< relref "/develop/connect/clients/client-side-caching" >}}) for
[client side caching documentation]({{< relref "/develop/clients/client-side-caching" >}}) for
background information.

When tracking is enabled Redis, using the [`CLIENT TRACKING`]({{< relref "/commands/client-tracking" >}}) command, it is
Expand Down
2 changes: 1 addition & 1 deletion content/commands/client-getredir/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ syntax_str: ''
title: CLIENT GETREDIR
---
This command returns the client ID we are redirecting our
[tracking]({{< relref "/develop/connect/clients/client-side-caching#tracking" >}}) notifications to. We set a client
[tracking]({{< relref "/develop/clients/client-side-caching#tracking" >}}) notifications to. We set a client
to redirect to when using [`CLIENT TRACKING`]({{< relref "/commands/client-tracking" >}}) to enable tracking. However in
order to avoid forcing client libraries implementations to remember the
ID notifications are redirected to, this command exists in order to improve
Expand Down
2 changes: 1 addition & 1 deletion content/commands/client-tracking/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ syntax_str: "[REDIRECT\_client-id] [PREFIX\_prefix [PREFIX prefix ...]] [BCAST]
title: CLIENT TRACKING
---
This command enables the tracking feature of the Redis server, that is used
for [server assisted client side caching]({{< relref "/develop/connect/clients/client-side-caching#tracking" >}}).
for [server assisted client side caching]({{< relref "/develop/clients/client-side-caching#tracking" >}}).

When tracking is enabled Redis remembers the keys that the connection
requested, in order to send later invalidation messages when such keys are
Expand Down
2 changes: 1 addition & 1 deletion content/commands/client-trackinginfo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ syntax_fmt: CLIENT TRACKINGINFO
syntax_str: ''
title: CLIENT TRACKINGINFO
---
The command returns information about the current client connection's use of the [server assisted client side caching]({{< relref "/develop/connect/clients/client-side-caching" >}}) feature.
The command returns information about the current client connection's use of the [server assisted client side caching]({{< relref "/develop/clients/client-side-caching" >}}) feature.

Here's the list of tracking information sections and their respective values:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
aliases: /develop/connect/clients
categories:
- docs
- develop
Expand All @@ -9,10 +10,11 @@ categories:
- oss
- kubernetes
- clients
hideListLinks: true
description: Connect your application to a Redis database and try an example
linkTitle: Clients
title: Connect with Redis clients
weight: 45
linkTitle: Client APIs
title: Connect with Redis client API libraries
weight: 30
---

Use the Redis client libraries to connect to Redis servers from
Expand All @@ -21,17 +23,17 @@ for six main languages:

| Language | Client name | Docs | Supported |
| :-- | :-- | :-- | :-- |
| [Python](https://www.python.org/) | [`redis-py`](https://github.com/redis/redis-py) |[Redis Python library guide]({{< relref "/develop/connect/clients/python/redis-py" >}}) | Yes |
| [Python](https://www.python.org/) | [`redis-py`](https://github.com/redis/redis-py) |[`redis-py` guide]({{< relref "/develop/clients/redis-py" >}}) | Yes |
| [Python](https://www.python.org/) | [`RedisVL`](https://github.com/redis/redis-vl-python) |[RedisVL guide]({{< relref "/integrate/redisvl" >}}) | Yes
| [C#/.NET](https://learn.microsoft.com/en-us/dotnet/csharp/) | [`NRedisStack`](https://github.com/redis/NRedisStack) |[C#/.NET guide]({{< relref "/develop/connect/clients/dotnet" >}}) | Yes |
| [Node.js](https://nodejs.org/en) | [`node-redis`](https://github.com/redis/node-redis) | [Node.js guide]({{< relref "/develop/connect/clients/nodejs" >}}) | Yes |
| [Java](https://www.java.com/en/) | [`Jedis`](https://github.com/redis/jedis) | [Jedis guide]({{< relref "/develop/connect/clients/java/jedis" >}}) | Yes |
| [Java](https://www.java.com/en/) | [`Lettuce`](https://github.com/redis/lettuce) | [Lettuce guide]({{< relref "/develop/connect/clients/java/lettuce" >}}) | Yes |
| [Go](https://go.dev/) | [`go-redis`](https://github.com/redis/go-redis) | [Go guide]({{< relref "/develop/connect/clients/go" >}}) | Yes |
| [PHP](https://www.php.net/)| [`Predis`](https://github.com/predis/predis) | [PHP guide]({{< relref "/develop/connect/clients/php" >}}) | No |
| [C#/.NET](https://learn.microsoft.com/en-us/dotnet/csharp/) | [`NRedisStack`](https://github.com/redis/NRedisStack) |[`NRedisStack` guide]({{< relref "/develop/clients/dotnet" >}}) | Yes |
| [Node.js](https://nodejs.org/en) | [`node-redis`](https://github.com/redis/node-redis) | [`node-redis` guide]({{< relref "/develop/clients/nodejs" >}}) | Yes |
| [Java](https://www.java.com/en/) | [`Jedis`](https://github.com/redis/jedis) | [`Jedis` guide]({{< relref "/develop/clients/jedis" >}}) | Yes |
| [Java](https://www.java.com/en/) | [`Lettuce`](https://github.com/redis/lettuce) | [`Lettuce` guide]({{< relref "/develop/clients/lettuce" >}}) | Yes |
| [Go](https://go.dev/) | [`go-redis`](https://github.com/redis/go-redis) | [`go-redis` guide]({{< relref "/develop/clients/go" >}}) | Yes |
| [PHP](https://www.php.net/)| [`Predis`](https://github.com/predis/predis) | [`Predis` guide]({{< relref "/develop/clients/php" >}}) | No |

We also provide several higher-level
[object mapping (OM)]({{< relref "/develop/connect/clients/om-clients" >}})
[object mapping (OM)]({{< relref "/develop/clients/om-clients" >}})
libraries for [Python]({{< relref "/integrate/redisom-for-python" >}}),
[C#/.NET]({{< relref "/integrate/redisom-for-net" >}}),
[Node.js]({{< relref "/integrate/redisom-for-node-js" >}}), and
Expand All @@ -56,7 +58,5 @@ You will need access to a Redis server to use these libraries.
You can experiment with a local installation of Redis Stack
(see [Install Redis Stack]({{< relref "/operate/oss_and_stack/install/install-stack/" >}})) or with a free trial of [Redis Cloud]({{< relref "/operate/rc" >}}).
To interact with a Redis server without writing code, use the
[Redis CLI]({{< relref "/develop/connect/cli" >}}) and
[Redis Insight]({{< relref "/develop/connect/insight" >}}) tools.

## Client library guides
[Redis CLI]({{< relref "/develop/tools/cli" >}}) and
[Redis Insight]({{< relref "/develop/tools/insight" >}}) tools.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
aliases: /develop/connect/clients/client-side-caching
categories:
- docs
- develop
Expand Down
91 changes: 91 additions & 0 deletions content/develop/clients/dotnet/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
aliases: /develop/connect/clients/dotnet
categories:
- docs
- develop
- stack
- oss
- rs
- rc
- oss
- kubernetes
- clients
description: Connect your .NET application to a Redis database
linkTitle: NRedisStack (C#/.NET)
title: NRedisStack guide (C#/.NET)
weight: 3
---

[NRedisStack](https://github.com/redis/NRedisStack) is the .NET client for Redis.
The sections below explain how to install `NRedisStack` and connect your application
to a Redis database.

`NRedisStack` requires a running Redis or [Redis Stack]({{< relref "/operate/oss_and_stack/install/install-stack/" >}}) server. See [Getting started]({{< relref "/operate/oss_and_stack/install/" >}}) for Redis installation instructions.

You can also access Redis with an object-mapping client interface. See
[Redis OM for .NET]({{< relref "/integrate/redisom-for-net" >}})
for more information.

## Install

Using the `dotnet` CLI, run:

```bash
dotnet add package NRedisStack
```

## Connect and test

Connect to localhost on port 6379.

```csharp
using NRedisStack;
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;
//...
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
```

You can test the connection by storing and retrieving a simple string.

```csharp
db.StringSet("foo", "bar");
Console.WriteLine(db.StringGet("foo")); // prints bar
```

Store and retrieve a HashMap.

```csharp
var hash = new HashEntry[] {
new HashEntry("name", "John"),
new HashEntry("surname", "Smith"),
new HashEntry("company", "Redis"),
new HashEntry("age", "29"),
};
db.HashSet("user-session:123", hash);

var hashFields = db.HashGetAll("user-session:123");
Console.WriteLine(String.Join("; ", hashFields));
// Prints:
// name: John; surname: Smith; company: Redis; age: 29
```
## Redis Stack modules

To access Redis Stack capabilities, use the appropriate interface like this:

```
IBloomCommands bf = db.BF();
ICuckooCommands cf = db.CF();
ICmsCommands cms = db.CMS();
IGraphCommands graph = db.GRAPH();
ITopKCommands topk = db.TOPK();
ITdigestCommands tdigest = db.TDIGEST();
ISearchCommands ft = db.FT();
IJsonCommands json = db.JSON();
ITimeSeriesCommands ts = db.TS();
```

## More information

See the other pages in this section for more information and examples.
148 changes: 148 additions & 0 deletions content/develop/clients/dotnet/connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
---
categories:
- docs
- develop
- stack
- oss
- rs
- rc
- oss
- kubernetes
- clients
description: Connect your .NET application to a Redis database
linkTitle: Connect
title: Connect to the server
weight: 2
---

## Basic connection

You can connect to the server simply by passing a string of the
form "hostname:port" to the `Connect()` method (for example,
"localhost:6379"). However, you can also connect using a
`ConfigurationOptions` parameter. Use this to specify a
username, password, and many other options:

```csharp
using NRedisStack;
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;

ConfigurationOptions conf = new ConfigurationOptions {
EndPoints = { "localhost:6379" },
User = "yourUsername",
Password = "yourPassword"
};

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(conf);
IDatabase db = redis.GetDatabase();

db.StringSet("foo", "bar");
Console.WriteLine(db.StringGet("foo")); // prints bar
```

## Connect to a Redis cluster

The basic connection will use the
[Cluster API]({{< relref "/operate/rs/clusters/optimize/oss-cluster-api" >}})
if it is available without any special configuration. However, if you know
the addresses and ports of several cluster nodes, you can specify them all
during connection in the `Endpoints` parameter:

```csharp
ConfigurationOptions options = new ConfigurationOptions
{
//list of available nodes of the cluster along with the endpoint port.
EndPoints = {
{ "localhost", 16379 },
{ "localhost", 16380 },
// ...
},
};

ConnectionMultiplexer cluster = ConnectionMultiplexer.Connect(options);
IDatabase db = cluster.GetDatabase();

db.StringSet("foo", "bar");
Console.WriteLine(db.StringGet("foo")); // prints bar
```

## Connect to your production Redis with TLS

When you deploy your application, use TLS and follow the [Redis security]({{< relref "/operate/oss_and_stack/management/security/" >}}) guidelines.

Before connecting your application to the TLS-enabled Redis server, ensure that your certificates and private keys are in the correct format.

To convert user certificate and private key from the PEM format to `pfx`, use this command:

```bash
openssl pkcs12 -inkey redis_user_private.key -in redis_user.crt -export -out redis.pfx
```

Enter password to protect your `pfx` file.

Establish a secure connection with your Redis database using this snippet.

```csharp
ConfigurationOptions options = new ConfigurationOptions
{
EndPoints = { { "my-redis.cloud.redislabs.com", 6379 } },
User = "default", // use your Redis user. More info https://redis.io/docs/latest/operate/oss_and_stack/management/security/acl/
Password = "secret", // use your Redis password
Ssl = true,
SslProtocols = System.Security.Authentication.SslProtocols.Tls12
};

options.CertificateSelection += delegate
{
return new X509Certificate2("redis.pfx", "secret"); // use the password you specified for pfx file
};
options.CertificateValidation += ValidateServerCertificate;

bool ValidateServerCertificate(
object sender,
X509Certificate? certificate,
X509Chain? chain,
SslPolicyErrors sslPolicyErrors)
{
if (certificate == null) {
return false;
}

var ca = new X509Certificate2("redis_ca.pem");
bool verdict = (certificate.Issuer == ca.Subject);
if (verdict) {
return true;
}
Console.WriteLine("Certificate error: {0}", sslPolicyErrors);
return false;
}

ConnectionMultiplexer muxer = ConnectionMultiplexer.Connect(options);

//Creation of the connection to the DB
IDatabase conn = muxer.GetDatabase();

//send SET command
conn.StringSet("foo", "bar");

//send GET command and print the value
Console.WriteLine(conn.StringGet("foo"));
```

## Multiplexing

Although example code typically works with a single connection,
real-world code often uses multiple connections at the same time.
Opening and closing connections repeatedly is inefficient, so it is best
to manage open connections carefully to avoid this.

Several other
Redis client libraries use *connection pools* to reuse a set of open
connections efficiently. NRedisStack uses a different approach called
*multiplexing*, which sends all client commands and responses over a
single connection. NRedisStack manages multiplexing for you automatically.
This gives high performance without requiring any extra coding.
See
[Connection pools and multiplexing]({{< relref "/develop/clients/pools-and-muxing" >}})
for more information.
Loading
Loading