Herramientas de usuario

Herramientas del sitio


db:redis

¡Esta es una revisión vieja del documento!


Redis

First steps

Install

$ wget <desired redis version>
$ tar xzf <file>
$ cd <created folder>
$ make

Execute

Server

$ redis-server

Client

$ redis-cli

Data structures & commands

Other commands

  • ping, if everything is good, the server will respond pong.
  • select, to select one of the 16 databases that Redis manage.

Design (and use) patterns

Redis for Python

First steps

Install

$ pip install redis

Examples

import redis
r = redis.StrictRedis(host='192.168.0.100', db=0, socket_timeout=2)
r.set('foo', 'bar')
print r.get('foo')

Highlights

  • You can connect to several isolated interfaces changing db argument.
  • Redis instances are thread safe.
  • flushdb() will flush the database you are connected to (cleaning all the keys), while flushall() will clear all the keys in every database.
  • Connecting/disconnecting for each operation is too expensive, so it is much better to maintain the connection opened. With redis-py it can be done by declaring a pool of connections (ConnectionPool class). redis-py uses a connection pool to manage connections to a Redis server. By default, each Redis instance you create will in turn create its own connection pool. You can choose a concrete connection pool in the next way:
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
r = redis.Redis(connection_pool=pool)
  • You can obtain the keys calling the keys() function of an StricRedis object. It also accept a pattern…
r = redis.StrictRedis(host=YOUR_HOST, port=YOUR_PORT, db=YOUR_DB)
r.keys()
keys(pattern='*')

Notes

db/redis.1406824899.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)