Herramientas de usuario

Herramientas del sitio


db:redis

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
db:redis [2014/07/31 18:01]
alfred [Publish\Subscribe]
db:redis [2020/05/09 09:25] (actual)
Línea 7: Línea 7:
 $ cd <created folder> $ cd <created folder>
 $ make $ make
 +$ make install
 </​code>​ </​code>​
 ==== Execute ==== ==== Execute ====
Línea 62: Línea 63:
     * ''​delete''​ to delete an instance.     * ''​delete''​ to delete an instance.
  
 +==== DataTypes ====
 +
 +=== Strings ===
 +<code python>
 +>>>​ r.set('​nombre',​ '​Jhon'​)
 +True 
 +>>>​ r.set('​apellido',​ '​Doe'​)
 +True 
 +>>>​ r.set('​nombre:​codigo',​ '​123ASDF'​)
 +True
 +>>>​ r.get('​nombre'​)
 +'​Jhon'​
 +>>>​ r.get('​nombre'​)
 +'​Doe'​
 +>>>​ r.get('​nombre:​codigo'​)
 +123ASDF
 +</​code>​
 +
 +=== Lists ===
 +<code python>
 +>>>​ r.rpush('​list',​ '​1'​)
 +1L
 +>>>​ r.rpush('​list',​ '​2'​)
 +2L
 +>>>​ r.lrange('​list',​ '​0',​ '​2'​)
 +['​1',​ '​2'​]
 +</​code>​
 +
 +=== Sets ===
 +<code python>
 +>>>​ r.sadd('​conjunto',​ '​1'​)
 +
 +>>>​ r.sadd('​conjunto',​ '​2'​)
 +
 +>>>​ r.smembers('​conjunto'​)
 +set(['​1',​ '​2',​ '​23'​])
 +</​code>​
 +
 +=== Hashes ===
 +<code python>
 +>>>​ r.hset('​mihash',​ '​field1',​ '​hola'​)
 +1L
 +>>>​ r.hset('​mihash',​ '​field2',​ '​mundo'​)
 +1L 
 +>>>​ r.hget('​mihash',​ '​field1'​)
 +'​hola'​
 +>>>​ r.hgetall('​mihash'​)
 +{'​field2':​ '​mundo',​ '​field1':​ '​hola'​}
 +</​code>​
 ==== Connections ==== ==== Connections ====
 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: 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:
Línea 132: Línea 182:
 >>>​ p.subscribe(**{'​my-channel':​ my_handler}) >>>​ p.subscribe(**{'​my-channel':​ my_handler})
 </​code>​ </​code>​
-If your application is not interested in the (sometimes noisy) subscribe/​unsubscribe confirmation messages, you can ignore them by passing ignore_subscribe_messages=True to r.pubsub(). ​+If your application is not interested in the (sometimes noisy) subscribe/​unsubscribe confirmation messages, you can ignore them by passing ​''​ignore_subscribe_messages=True'' ​to r.pubsub(). ​
 ==== Notes ==== ==== Notes ====
   * redis-py can be used together with ''​Redis Sentinel''​ to discover Redis nodes. ​   * redis-py can be used together with ''​Redis Sentinel''​ to discover Redis nodes. ​
 ===== Notes ===== ===== Notes =====
 +  * A good GUI: [[http://​redisdesktop.com/​]]
db/redis.1406829710.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)