Showing posts with label Redis. Show all posts
Showing posts with label Redis. Show all posts

Friday, October 27, 2023

How to connect to OCI Redis cluster

Redis is a private service and accessible only within the VCN or appropriately peered VCNs.

 

You can connect to the OCI Redis Clusters using the cluster endpoints provided. 

 

To write to the redis cluster, connect using the Primary endpoint.

To read from the redis cluster, connect using the Replica endpoint.

 

You may choose a client library your programming language supports to connect to OCI Cache with Redis.

 

For example, Lettuce or Jedis for Java, redis-py for Python, node-redis for Node.js, go-redis for Go and so on.

 

You can use redis-cli to connect to Redis cluster. The redis-cli is a command-line based tool connect to your redis clusters which can also be used to get valuable insights from the redis cluster.

 

To use redis-cli comes included with the Redis package. You need to establish a secure TLS connection between the client/application and redis server. You should use redis-cli version 6 or above so that it supports the --tls switch to establish as secure TLS connection.

 

By default, redis version 5 is default in the stream on Oracle Linux 8.

 

[root@jay ~]# yum module list redis

Last metadata expiration check: 0:06:43 ago on Fri 27 Oct 2023 14:34:46 GMT.

Oracle Linux 8 Application Stream (x86_64)

Name                                     Stream                                     Profiles                                     Summary                                                             

redis                                    5 [d][e]                                   common [d]                                   Redis persistent key-value database                                 

redis                                    6                                          common [d]                                   Redis persistent key-value database                                 

 

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

[root@jay ~]#

 

To install Redis Version 6, you need to enable redis 6 module stream.

 

[root@jay ~]# yum module enable redis:6

Last metadata expiration check: 0:10:29 ago on Fri 27 Oct 2023 14:34:46 GMT.

Dependencies resolved.

======================================================================================================================================================================================================

 Package                                         Architecture                                   Version                                         Repository                                       Size

======================================================================================================================================================================================================

Enabling module streams:

 redis                                                                                          6                                                                                                   

 

Transaction Summary

======================================================================================================================================================================================================

 

Is this ok [y/N]: y

Complete!

[root@jay ~]#

 

However, if you end up with the following error: “Error: It is not possible to switch enabled streams of a module unless explicitly enabled via configuration option module_stream_switch.”, you need to uninstall previous redis versions and reset the redis module as follows.

 

[root@jay ~]# yum module enable redis:6

Last metadata expiration check: 0:07:49 ago on Fri 27 Oct 2023 14:34:46 GMT.

Dependencies resolved.

The operation would result in switching of module 'redis' stream '5' to stream '6'

Error: It is not possible to switch enabled streams of a module unless explicitly enabled via configuration option module_stream_switch.

It is recommended to rather remove all installed content from the module, and reset the module using 'yum module reset <module_name>' command. After you reset the module, you can install the other stream.

[root@jay ~]#

 

[root@jay ~]# yum module reset redis

Last metadata expiration check: 0:10:14 ago on Fri 27 Oct 2023 14:34:46 GMT.

Dependencies resolved.

======================================================================================================================================================================================================

 Package                                         Architecture                                   Version                                         Repository                                       Size

======================================================================================================================================================================================================

Resetting modules:

 redis                                                                                                                                                                                              

 

Transaction Summary

======================================================================================================================================================================================================

 

Is this ok [y/N]: y

Complete!

[root@jay ~]#

 

 

Once redis mode is reset and version 6 module is enabled, you may proceed with installing redis version 6 as follows.

 

[root@jay ~]# yum module install redis

Last metadata expiration check: 0:11:16 ago on Fri 27 Oct 2023 14:34:46 GMT.

Dependencies resolved.

======================================================================================================================================================================================================

 Package                              Architecture                          Version                                                                Repository                                    Size

======================================================================================================================================================================================================

Installing group/module packages:

 redis                                x86_64                                6.2.7-1.module+el8.7.0+20764+cc495aeb                                  ol8_appstream                                1.2 M

Installing module profiles:

 redis/common                                                                                                                                                                                       

 

Transaction Summary

======================================================================================================================================================================================================

Install  1 Package

 

Total download size: 1.2 M

Installed size: 4.3 M

Is this ok [y/N]: y

Downloading Packages:

redis-6.2.7-1.module+el8.7.0+20764+cc495aeb.x86_64.rpm                                                                                                                6.9 MB/s | 1.2 MB     00:00   

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Total                                                                                                                                                                 6.8 MB/s | 1.2 MB     00:00    

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

  Preparing        :                                                                                                                                                                              1/1

  Running scriptlet: redis-6.2.7-1.module+el8.7.0+20764+cc495aeb.x86_64                                                                                                                           1/1

  Installing       : redis-6.2.7-1.module+el8.7.0+20764+cc495aeb.x86_64                                                                                                                           1/1

  Running scriptlet: redis-6.2.7-1.module+el8.7.0+20764+cc495aeb.x86_64                                                                                                                           1/1

  Verifying        : redis-6.2.7-1.module+el8.7.0+20764+cc495aeb.x86_64                                                                                                                           1/1

 

Installed:

  redis-6.2.7-1.module+el8.7.0+20764+cc495aeb.x86_64                                                                                                                                                 

 

Complete!

[root@jay ~]#

 

You should now be able to connect to Redis cluster using redis-cli:

 

# redis-cli --tls -h <Redis Endpoint>

 

[root@jay ~]# redis-cli --tls -h amaaaaaa2ne4d2g6eiu32jva-p.redis.eu-frankfurt-1.oci.oraclecloud.com

amaaaaaa2ne4d2g6eiu32jva-p.redis.eu-frankfurt-1.oci.oraclecloud.com:6379>

amaaaaaa2ne4d2g6eiu32jva-p.redis.eu-frankfurt-1.oci.oraclecloud.com:6379> set key value

OK

amaaaaaa2ne4d2g6eiu32jva-p.redis.eu-frankfurt-1.oci.oraclecloud.com:6379> get key

"value"

amaaaaaa2ne4d2g6eiu32jva-p.redis.eu-frankfurt-1.oci.oraclecloud.com:6379> quit

[root@jay ~]#

 


 

OCI Redis Cache Endpoints

 OCI provisions private DNS endpoints for your Redis Cluster as follows.

 

- 1 Primary Endpoint always pointing to the Primary node. In case of a primary node failure, the primary endpoint will automatically failover to the new primary.

 

- 1 Replica Endpoint pointing to one of the Read replicas. If you have more than 1 read replica, the replica end point resolves to one of the read replicas randomly.

 

- Node Endpoints to all the Redis nodes. This will never change.

 

Example:

Primary Endpoint: amaaaaaa2ne4d2g6eiu32jva-p.redis.eu-frankfurt-1.oci.oraclecloud.com

Replica Endpoint: amaaaaaa2ne4d2g6eiu32jva-r.redis.eu-frankfurt-1.oci.oraclecloud.com

Node Endpoints:

amaaaaaa2ne4d2g6eiu32jva-0.redis.eu-frankfurt-1.oci.oraclecloud.com

amaaaaaa2ne4d2g6eiu32jva-1.redis.eu-frankfurt-1.oci.oraclecloud.com

amaaaaaa2ne4d2g6eiu32jva-2.redis.eu-frankfurt-1.oci.oraclecloud.com

 

 

You can see '-p' suffix to the hash prefix for the primary endpoint, '-r' to the replica endpoint and '-n' (node number 0,1,2,3,4,5) suffix to the node endpoints. This way you could identify the endpoints easily.

 

NOTE:

These endpoints are all private DNS names and hence not resolvable outside the VCN.

 

[root@jay ~]# dig amaaaaaa2ne4d2g6eiu32jva-p.redis.eu-frankfurt-1.oci.oraclecloud.com +noall +answer

amaaaaaa2ne4d2g6eiu32jva-p.redis.eu-frankfurt-1.oci.oraclecloud.com. 500 IN A 10.0.1.5

[root@jay ~]#

[root@jay ~]# dig amaaaaaa2ne4d2g6eiu32jva-r.redis.eu-frankfurt-1.oci.oraclecloud.com +noall +answer

amaaaaaa2ne4d2g6eiu32jva-r.redis.eu-frankfurt-1.oci.oraclecloud.com. 350 IN A 10.0.1.223

[root@jay ~]#

[root@jay ~]# dig amaaaaaa2ne4d2g6eiu32jva-0.redis.eu-frankfurt-1.oci.oraclecloud.com +noall +answer

amaaaaaa2ne4d2g6eiu32jva-0.redis.eu-frankfurt-1.oci.oraclecloud.com. 500 IN A 10.0.1.230

[root@jay ~]#

[root@jay ~]# dig amaaaaaa2ne4d2g6eiu32jva-1.redis.eu-frankfurt-1.oci.oraclecloud.com +noall +answer

amaaaaaa2ne4d2g6eiu32jva-1.redis.eu-frankfurt-1.oci.oraclecloud.com. 500 IN A 10.0.1.118

[root@jay ~]#