Redis Services
Apcera provides the Redis service type and gateway, and semantic pipeline, for integrating with Redis.
Redis is an open source key-value store that supports values of various types, including complex data structures like hashes.
- Creating Redis services
- Creating persistent Redis services
- Connecting to an existing Redis server
- Requirements for implementing Redis services
- Troubleshooting Redis services
Creating Redis services
Redis services do not use providers. You only have to create the service and the binding. Apcera provides a semantic pipeline for Redis against which you can inject connection logic. See Requirements for using Redis services.
When you bind a job to the Redis service, the resulting URI points to the semantic pipeline instance associated with the Redis protocol. But, to the bound job the connection appears to be directly to the Redis server.
To create a Redis service you use the following syntax:
apc service create <service name> --type redis
For example:
apc service create redis-service --type redis
╭────────────────────────────────────────────────────────╮
│ Service Creation Settings │
├───────────────┬────────────────────────────────────────┤
│ Service: │ service::/sandbox/admin::redis-service │
│ Service Type: │ redis │
╰───────────────┴────────────────────────────────────────╯
Is this correct? [Y/n]:
Creating service... done
Success!
apc service show redis-service
╭────────────────────┬─────────────────────────────────────────╮
│ Service: │ redis-service │
├────────────────────┼─────────────────────────────────────────┤
│ FQN: │ service::/sandbox/admin::redis-service │
│ Type: │ redis │
│ Completion Status: │ created │
│ │ │
│ Created by: │ admin@apcera.me │
│ Created at: │ 2016-04-05 05:45:14.036339863 +0000 UTC │
╰────────────────────┴─────────────────────────────────────────╯
To bind a job named redis-cli
to the redis-service
you created:
apc service bind redis-service --job redis-cli
Creating persistent Redis services
The Redis service gateway supports the use of the persistence_provider
option. You can persist Redis data if you create the Redis service using a persistence provider.
For example, to create a persistent Redis service using an NFS provider:
apc service create redis-nfs --type redis -- --persistence_provider provider::/apcera/providers::apcfs
╭────────────────────────────────────────────────────╮
│ Service Creation Settings │
├───────────────┬────────────────────────────────────┤
│ Service: │ service::/sandbox/admin::redis-nfs │
│ Service Type: │ redis │
╰───────────────┴────────────────────────────────────╯
Is this correct? [Y/n]:
Creating service... done
Success!
apc service show redis-nfs
╭────────────────────┬────────────────────────────────────────╮
│ Service: │ redis-nfs │
├────────────────────┼────────────────────────────────────────┤
│ FQN: │ service::/sandbox/admin::redis-nfs │
│ Type: │ redis │
│ Completion Status: │ created │
│ │ │
│ Created by: │ admin@apcera.me │
│ Created at: │ 2016-04-05 06:36:48.94678241 +0000 UTC │
╰────────────────────┴────────────────────────────────────────╯
See Apcera File Share services for details on using NFS persistence.
Connecting to an existing Redis server
You can use the Generic service type and gateway to connect to an existing Redis server.
Requirements for implementing Redis services
This section describes the requirements for implementing Redis services.
Service gateway
To create Redis services, the redis
service gateway is required.
To verify that you have the redis
service gateway:
apc gateway list -ns /
Working in "/"
╭──────────┬──────────┬──────────────────────────┬─────────┬───────────╮
│ Name │ Type │ Namespace │ Status │ Instances │
├──────────┼──────────┼──────────────────────────┼─────────┼───────────┤
│ generic │ generic │ /apcera/service-gateways │ started │ 1/1 │
│ gnatsd │ gnatsd │ /apcera/service-gateways │ started │ 1/1 │
│ http │ http │ /apcera/service-gateways │ started │ 1/1 │
│ ipm │ ipm │ /apcera/service-gateways │ started │ 1/1 │
│ memcache │ memcache │ /apcera/service-gateways │ started │ 1/1 │
│ mongodb │ mongodb │ /apcera/service-gateways │ started │ 1/1 │
│ mysql │ mysql │ /apcera/service-gateways │ started │ 1/1 │
│ network │ network │ /apcera/service-gateways │ started │ 1/1 │
│ nfs │ nfs │ /apcera/service-gateways │ started │ 1/1 │
│ postgres │ postgres │ /apcera/service-gateways │ started │ 1/1 │
│ rabbitmq │ rabbitmq │ /apcera/service-gateways │ started │ 1/1 │
│ redis │ redis │ /apcera/service-gateways │ started │ 1/1 │
│ s3 │ s3 │ /apcera/service-gateways │ started │ 1/1 │
╰──────────┴──────────┴──────────────────────────┴─────────┴───────────╯
Semantic pipeline
Apcera provides a semantic pipeline for the Redis protocol. To verify that you have the Redis semantic pipeline:
apc pipeline list -ns /
Working in "/"
╭──────────┬──────┬────────────────────────────┬────────╮
│ Name │ Type │ Namespace │ Status │
├──────────┼──────┼────────────────────────────┼────────┤
│ http │ job │ /apcera/semantic-pipelines │ ready │
│ memcache │ job │ /apcera/semantic-pipelines │ ready │
│ mysql │ job │ /apcera/semantic-pipelines │ ready │
│ postgres │ job │ /apcera/semantic-pipelines │ ready │
│ redis │ job │ /apcera/semantic-pipelines │ ready │
╰──────────┴──────┴────────────────────────────┴────────╯
When you bind a job to a Redis service, an instance of the redis
semantic pipeline is attached to the job and brokers the connection.
Policy
Policy is required to use a redis
service gateway to create services and to view that the persistence_provider
option is enabled.
The following claims are supported:
on gateway::/apcera/service-gateways::redis {
{ permit use }
{ serviceParam persistence_provider }
}
The permit use
claim on the redis
gateway lets you create Redis services.
The serviceParam persistence_provider
claim on the redis
gateway lets you view the persistence provider.
For example, with both the --persistence_provider
option enabled and the serviceParam persistence_provider
claim in place, apc service show
provides the following information:
apc service show redis-nfs
╭───────────────────────┬────────────────────────────────────────╮
│ Service: │ redis-nfs │
├───────────────────────┼────────────────────────────────────────┤
│ FQN: │ service::/sandbox/admin::redis-nfs │
│ Type: │ redis │
│ persistence_provider: │ provider::/apcera/providers::apcfs │
│ Completion Status: │ created │
│ │ │
│ Created by: │ admin@apcera.me │
│ Created at: │ 2016-04-05 06:36:48.94678241 +0000 UTC │
╰───────────────────────┴────────────────────────────────────────╯
Lastly, to consume Redis services, both the service and the job must have permit bind
policy claims. See service policy examples.
Troubleshooting Redis services
The following troubleshooting steps demonstrate one technique for debugging Redis services.
-
Create the redis-service as described above.
-
Attach a TCP route to port 6379.
apc route add auto --tcp --job redis/redis-service
- Retrieve the resolved TCP address/port pair:
apc job show redis/redis-service
Job | redis/redis-svc |
---|---|
. . . . | . . . . . . . . . . |
Route: | tcp://54.213.232.162:58999 [to port 6379] |
. . . . | . . . . . . . . . . |
- Create a capsule.
apc capsule create redis-cli -ae
- Connect to the capsule and install redis-cli.
apc capsule connect redis-cli
-bash-4.3# apt-get update
-bash-4.3# sudo apt-get install redis-tools
- Use
redis-cli
to connect to Redis.
The following command connects you to a shell where you can debug your Redis database:
redis-cli -h 54.213.232.162 -p 58999