Using a9s Redis

This topic describes how to use a9s Redis.

Use a9s Redis with an Application

To use a9s Redis with an application, create a service instance and bind the service instance to your app. For more information about managing service instances, see Managing Service Instances with the cf CLI.

View the a9s Redis Service

After the tile is installed, you can see the a9s-redis32 and its service plans appear in your CF marketplace. Run cf marketplace to see the service listing:

´´´bash $ cf marketplace Getting services from marketplace in org test / space test as admin… OK service plans description a9s-redis32 redis-single-small, redis-single-big, redis-cluster-small, redis-cluster-big This is the anynines Redis 32 service. ´´´

Create a Service Instance

To provision a Redis database, run cf create-service.

´´´bash $ cf create-service a9s-redis32 redis-single-small my-redis-service ´´´

Depending on your infrastructure and service broker utilization, it might take several minutes to create the service instance.

Run cf services to view the creation status. This command displays a list of all your service instances. To view the status of a specific service instance, run cf service NAME-OF-YOUR-SERVICE.

Bind an Application to a Service Instance

After your database is created, run cf bind-service to bind the service to your application:

´´´bash $ cf bind-service a9s-redis-app my-redis-service ´´´

Restage or Restart Your Application

To enable your application to access the service instance, run cf restage or cf restart to restage or restart your application.

Obtain Service Instance Access Credentials

After a service instance is bound to an application, the credentials of your Redis database are stored in the environment variables of the application. Run cf env APP-NAME to display the environment variables.

You can find the credentials in the VCAP_SERVICES key.

´´´bash $ cf env a9s-redis-app Getting env variables for app a9s-redis-app in org test / space test as admin… OK

System-Provided: { “VCAP_SERVICES”: { “a9s-redis”: [ { “credentials”: { “dns_servers”: [ “172.28.10.22”, “172.28.11.11”, “172.28.12.11” ], “host”: [ “d67901c.service.dc1.a9svs” ], “host_ip”: [ “172.28.25.12” ], “port”: 6379 “password”: “a9s-brk-usr”, “username”: “a9s-password” }, “label”: “a9s-redis”, “name”: “my-redis-service”, “plan”: “redis-single-non-persistent-small”, } ] } } … ´´´

You can use the host_ip, username, and password values to connect to your database with a Redis client.

a9s Redis for PCF comes with its own Consul cluster to provide hostname resolving. When your DNS is configured to resolve the a9s Redis for PCF service instance domains, you can make use of host. For more information, see Name Resolving With Consul.

Delete an a9s Redis Service Instance

WARNING: Before deleting a service instance, you must back up data stored in your database. This operation cannot be undone and all the data is lost when the service is deleted.

Before you can delete a service instance, you must unbind it from all apps.

List Available Services

Run cf services to list available services.

´´´bash $ cf services

Getting services in org test / space test as admin… OK

name service plan bound apps last operation my-redis-service a9s-redis redis-single-small a9s-redis-app create succeeded ´´´

This example shows that my-redis-service is bound to the a9s-redis-app application.

Unbind a Service Instance

Run cf unbind-service to unbind the service from your app:

´´´bash $ cf unbind-service a9s-redis-app my-redis-service ´´´

Delete a Service Instance

After unbinding the service, it is no longer bound to an app. Run cf delete-service to delete the service:

´´´bash $ cf delete-service my-redis-service ´´´

It may take several minutes to delete the service. Deleting a service deprovisions the corresponding infrastructure resources. Run the cf services command to view the deletion status.

Upgrade the Service Instance to Another Service Plan

Once created, you can upgrade your service instance to another, larger service plan. A larger service plan provides more CPU, RAM and storage. For more information, see the Update a Service Instance of the Managing Service Instances with the cf CLI topic.

´´´bash $ cf update-service my-redis-service -p a-bigger-plan ´´´

Here are the plans you can upgrade to, depending on the one you are currently using:

  • If you are currently using the redis-single-small plan, you can upgrade to redis-single-big plan.
  • If you are currently using the redis-cluster-small plan, you can upgrade to redis-cluster-big plan.

Change RDB Persistence Settings

a9s Redis supports RDB persistence with point-in-time snapshots. This setting can be changed by the user.

Default Behavior

Setting Effect
save 900 1 Create a snapshot after 900 seconds if 1 write operations occurred.
save 300 10 Create a snapshot after 300 seconds if 10 write operations occurred.
save 60 10000 Create a snapshot after 300 seconds if 10 write operations occurred.

Configuring RDB

You can configure RDB according to the needs of your apps by providing customer settings. This setting must follow the original Redis configuration for RDB -c {"snapshot": "['save 900 1', 'save 300 10']"}.

´´´bash $ cf update-service my-redis-service -c {“snapshot”: “[‘save 900 1’, 'save 300 10’]”} ´´´

In this example, it is configured to snapshot the Redis database according to the following rules:

Setting Effect
save 900 1 Create a snapshot after 900 seconds if 1 write operations occurred.
save 300 10 Create a snapshot after 300 seconds if 10 write operations occurred.

Cache Only

You can disable snapshots and use Redis as cache only by creating the service with the following customer setting -c '{"snapshot": "[]"}'.

´´´bash $ cf update-service my-redis-service -c {“snapshot”: “[]”} ´´´

For more information, see the snapshot settings in the documentation of Redis Persistence.

Change Maxmemory Policy

With the maxmemory_policy, you can configure a9s Redis which key to remove when maxmemory is reached. Ther are several configurable behaviors. noeviction is the default.

Setting Effect
volatile-lru Remove the key with an expire set using an LRU algorithm
allkeys-lru Remove any key according to the LRU algorithm
volatile-random Remove a random key with an expire set
allkeys-random Remove any random key
volatile-ttl Remove the key with the nearest expire time (minor TTL)
noeviction Do not expire at all, just return an error on write operations

You can use -c {"maxmemory_policy": "volatile-ttl"} to update the maxmemory-policy.

´´´bash $ cf update-service my-redis-service -c {“maxmemory_policy”: “volatile-ttl”} ´´´

For more information, see the maxmemory-policy settings in the self documented redis.conf.

HA Cluster with Redis Sentinel

a9s Redis uses Redis Sentinel to provide a high available replication set. Redis Sentinel monitors the several nodes, takes care of automatic failover, and sends notifcation when something in the cluster changes.

a9s Redis provides two settings to adjust the cluster behaviour, min_slaves_max_lag and down_after_milliseconds.

Setting Effect
min_slaves_max_lag Time in seconds the master waits before it stops accepting writes when slaves are no more reachable. Default is 10 seconds. min-slaves-to-write is set to 1 and cannot be changed. See redis.conf.
down_after_milliseconds Number of milliseconds the master should be unreachable in order to consider it in S_DOWN state. Default is 30000 ms. See sentinel.conf.

´´´bash $ cf update-service my-redis-service -c {“min_slaves_max_lag”: “10”} ´´´

´´´bash $ cf update-service my-redis-service -c {“down_after_milliseconds”: “30000”} ´´´

Add a Graphite Endpoint

If you want to monitor your service with Graphite, you can set an endpoint to where to information will be sent with the cf update-service command. This command expects the -c flag and a JSON string containing the graphite and metrics_prefix keys. Depending on your graphite provider, the metrics_prefix might require that each metric must start with an API key in their name. You can also change the interval within the data is send to the endpoint. To do this, modify interval; the default is 10s.

$ cf update-service my-redis-service -c '{ "graphite": ["yourspace.your-graphite-endpoint.com:12345"], "metrics_prefix": "your-api-key.my-cluster-redis", "interval": "5"}'

Add a Syslog Endpoint

The cf update-service command used with the -c flag can let you stream your syslog to a third-party service. In this case, the command expects a JSON string containing the syslog key. You can also change the interval for the syslog with the same key than for the graphite endpoint interval.

$ cf update-service my-redis-service -c '{ "syslog": ["logs4.your-syslog-endpoint.com:54321"], "interval": "5" }'

Cloud Foundry Application Security Groups

This topic describes how to check whether a security group was created.

Each a9s Data Service will automatically create and update Cloud Foundry security groups in order to protect service instances to be accessed by applications not running in the same Cloud Foundry applications space. To understand Security Groups, see Understanding Application Security Groups.

Get Service Instance GUID

Run cf service INSTANCE_NAME --guid to get the guid of the service instance.

$ cf service my-redis --guid
ca16f111-5073-40b7-973a-156c75dd3028

Check Available Security Groups

To see all available security groups, run cf security-groups.

$cf security-groups
Getting security groups as demo@anynines.com
OK

     Name                                         Organization     Space
#0   public_networks
#1   dns
#2   tcp_open
#3   guard_432fb752-876d-443b-a311-a075f4df2237   demonstrations   demo
#4   guard_ca16f111-5073-40b7-973a-156c75dd3028   demonstrations   demo

There we can see a security group with the named guard_ca16f111-5073-40b7-973a-156c75dd3028 was successfully created.

Note: In some circumstances, the connection between the application and the service instance is not possible. In this case, check to see if a security group was created.

Back Up and Restore Service Instances

a9s Redis provides an easy way to create backups and restore if needed.

Get Dashboard Address, Log In, and Authorize

  1. Get the dashboard URL with cf service SERVICE-NAME. “`bash $cf service my-redis

Service instance: my-redis Service: a9s-redis Bound apps: Tags: Plan: redis-single-small Description: This is a service creating and managing dedicated Redis service instances and clusters, powered by the anynines Service Framework Documentation url: Dashboard: https://a9s-redis-dashboard.aws.ie.a9s.eu/service-instances/ca16f111-5073-40b7-973a-156c75dd3028

Last Operation Status: update succeeded Message: Started: 2017-10-26T08:28:38Z Updated: 2017-10-26T08:28:38Z ”`

  1. Browse to the dashboard URL and authenticate on the redirected page with your Cloud Foundry credentials: Authentication page

  2. Click Authorize to approve the authorization request: Authorization page

Perform a Backup

On the dashboard, you can trigger a backup by clicking Trigger backup.

Service dashboard

After a short period of time, the backup will be queued and the backup process will soon start.

Service dashboard bkp triggered

Note: Depending on the size of the data, the backup will take some time.

Restore a Backup

  1. Open the dashboard again and select the backup you would like to restore.

  2. Click Restore and wait for the restore to trigger.

service-dashboard

Note: Depending on the size of the data, the restore will take some time.

service-dashboard

Make a Service Instance Locally Available

It is possible to access any of the a9s Data Services locally. You can connect with a local client to the service for any purpose, such as debugging. CF provides a smart way to create SSH forward tunnels through a pushed application. For more information about this feature, see the Accessing Apps with SSH section of the CF documentation.

First, you must have an application bound to the service. To do this, see Bind an Application to a Service Instance.

Note: `cf ssh` support must be enabled in the platform. Your administrator can tell you whether it is enabled.

Get the Service URL and Credentials

You must first follow the procedure in Obtain Service Instance Access Credentials to get the hostname of the service and the user credentials.

$ cf env a9s-redis-app
Getting env variables for app a9s-redis-app in org test / space test as admin...
OK

System-Provided:
{
  "VCAP_SERVICES": {
   "a9s-redis": [
    {
      "credentials": {
        "dns_servers": [
          "172.28.10.22",
          "172.28.11.11",
          "172.28.12.11"
        ],
        "host": [
          "d67901c.service.dc1.a9svs"
        ],
        "host_ip": [
          "172.28.25.12"
        ],
        "port": 6379
        "password": "a9s-brk-usr",
        "username": "a9s-password"
     },
     "label": "a9s-redis",
     "name": "my-redis-service",
     "plan": "redis-cluster-small"
    }
   ]
  }
}
...

Note the host d67901c.service.dc1.a9svs, the username a9s-brk-usr, and the password a9s-password. You will need these in the next step.

Create a Tunnel to the Service

With cf ssh, you can create am SSH forward tunnel to the management dashboard. Use port 6379 to connect to the a9s Redis Instance.

$ cf ssh a9s-redis-app -L 6379:d67901c.service.dc1.a9svs:6379
vcap@956aaf4e-6da9-4f69-4b1d-8e631a403312:~$

When the SSH tunnel is open, you can access the instance using the address localhost:6379.

Note: Be sure to close the session by running exit.

Create a pull request or raise an issue on the source for this page in GitHub