[go: nahoru, domu]

Skip to content

opencensus-integrations/ocredispy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ocredis

ocredis is a wrapper for the popular [redis-py](https://github.com/andymccurdy/redis-py)

ocredis provides observability using OpenCensus for distributed tracing and metrics.

Installing it

pip install ocredis

Using it

You can initialize exactly how you would for redis.Redis. In fact it is meant to be a drop replacement.

  • Change the import statement from
>>> import redis

to

>>> import ocredis
  • Change the client initialization from
>>> client = redis.Redis(host=host, port=port)

to

>>> client = ocredis.OcRedis(host=host, port=port)`

and obviously enabling OpenCensus metrics and exporters as per https://opencensus.io/exporters/supported-exporters/python/

>>> ocredis.register_views()

and the rest is trivial to use then.

For example

>>> import ocredis
>>> ocredis.register_views()
>>> r = ocredis.OcRedis(host='localhost', port=6379)
>>> r.set('foo', 'bar')
True
>>> r.get('foo')
'bar'

Metrics available

  • calls
  • latency
  • key_length
  • value_length
Metric View Name Unit Tags
Latency redispy/latency ms 'error', 'method', 'status'
Calls redispy/calls 1 'error', 'method', 'status'
Key lengths redispy/key_length By 'error', 'method', 'status'
Value lengths redispy/value_length By 'error', 'method', 'status'

Tests

Tests can be run by using pytest, for example

pytest