Questions tagged [redis-py]

A Python interface to the Redis key-value store.

A Python interface to the Redis key-value store.

redis-py is developed and maintained by Andy McCurdy (sedrik@gmail.com).

It can be installed in your python environment using pip install redis or if you download the source from above link you can run python setup.py install

221 questions
65
votes
10 answers

Redis Python - how to delete all keys according to a specific pattern In python, without python iterating

I'm writing a django management command to handle some of our redis caching. Basically, I need to choose all keys, that confirm to a certain pattern (for example: "prefix:*") and delete them. I know I can use the cli to do that: redis-cli KEYS…
alonisser
  • 11,542
  • 21
  • 85
  • 139
35
votes
2 answers

redis-python db=0 parameter used for?

I have read the redis-python document and searched online, I can not find anything about the db parameter for Redis(). What is it use for?
kun
  • 3,917
  • 3
  • 15
  • 21
34
votes
11 answers

Is non-blocking Redis pubsub possible?

I want to use redis' pubsub to transmit some messages, but don't want be blocked using listen, like the code below: import redis rc = redis.Redis() ps = rc.pubsub() ps.subscribe(['foo', 'bar']) rc.publish('foo', 'hello world') for item in…
limboy
  • 3,879
  • 7
  • 37
  • 53
27
votes
1 answer

What are equivalent functions of MULTI and EXEC commands in redis-py?

I tested all the transaction commands (MULTI, EXEC, WATCH, DISCARD) in redis-cli. But when i tried with redis-py the following error occurred: AttributeError: 'Redis' object has no attribute 'multi' I have tried the following code snippet: import…
Ahsanul Haque
  • 10,676
  • 4
  • 41
  • 57
21
votes
3 answers

redis-py and hgetall behavior

I played around with flask microframework, and wanted to cache some stats in redis. Let's say I have this dict: mydict = {} mydict["test"] = "test11" I saved it to redis with redis.hmset("test:key", mydict) However after restore stored =…
Tommi
  • 3,199
  • 1
  • 24
  • 38
19
votes
2 answers

How to use sadd with multiple elements in Redis using Python API?

Please consider the following example >>import redis >>redis_db_url = '127.0.0.1' >>r = redis.StrictRedis(host = redis_db_url,port = 6379,db = 0) >>r.sadd('a',1) >>r.sadd('a',2) >>r.sadd('a',3) >>r.smembers('a') [+] output: set(['1', '3',…
Sourav Sarkar
  • 406
  • 1
  • 5
  • 14
18
votes
2 answers

How to set the redis timeout waiting for the response with pipeline in redis-py?

In the code below, is the pipeline timeout 2 seconds? client = redis.StrictRedis(host=host, port=port, db=0, socket_timeout=2) pipe = client.pipeline(transaction=False) for name in namelist: key = "%s-%s-%s-%s" % (key_sub1, key_sub2, name,…
hupantingxue
  • 2,134
  • 3
  • 19
  • 24
15
votes
2 answers

Redis-python setting multiple key/values in one operation

Currently I use the basic mset feature to store a key/value; from common.redis_client import get_redis_client cache = get_redis_client() for k,v in some_dict.items(): kw = {'key': value} cache.mset(kw) #later: cache.get('key') I store…
alonisser
  • 11,542
  • 21
  • 85
  • 139
13
votes
1 answer

redis python psubscribe to event with callback, without calling .listen()

I'm trying to subscribe to keyspace event in redis using python. I hope to NOT use the for-loop with .listen() after calling .psubscribe(). Is this possible? I have enabled all keyspace events with KEA. def subscribe(self, key, handler): #…
Keven Wang
  • 1,208
  • 17
  • 28
13
votes
2 answers

redis.exceptions.ConnectionError: Error -2 connecting to localhost:6379. Name or service not known

I have this error when I run my code in server, my env is debian, and Python2.7.3 Traceback (most recent call last): File "fetcher.py", line 4, in import mirad.fetcher_tasks as tasks File…
Vahid Kharazi
  • 5,723
  • 17
  • 60
  • 103
11
votes
1 answer

redis locking: redispy vs python-redis-lock

Except that python-redis-lock module provides contextmanager for the lock object - what are the differences when compared to the lock object you get from redispy module? what is so special about python-redis-lock? rc =…
Murali Mopuru
  • 6,086
  • 5
  • 33
  • 51
11
votes
5 answers

How to insert Billion of data to Redis efficiently?

I have around 2 billion key-value pairs and I want to load them into Redis efficiently. I am currently using Python and used Pipe as documented by the redis-py. How can I speed the following approach up? import redis def load(pdt_dict): """ …
John Deep
  • 161
  • 1
  • 2
  • 10
10
votes
1 answer

Correct Way of using Redis Connection Pool in Python

How should two different modules foo.py and bar.py get a connection from a Redis connection pool? In other words, how should we structure the app? I believe the goal is to have just a single connection pool for all modules to get a connection…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
9
votes
3 answers

Does the redis-py module work with Redis in Cluster mode?

I'm trying to use redis-py with redis in cluster mode, but I can't get it to work. I see that redis-py-cluster works, but I have a preference for redis-py as I have been using it and it's a recommended client.
pettinato
  • 1,472
  • 2
  • 19
  • 39
7
votes
2 answers

pythonic way deal with DataError: Invalid input of type: 'dict'. Convert to a bytes, string, int or float first.?

redis veersion 3.4.1 must be use hash, can't use str or other data type data: { '_anno': { 'ctp': 'list', 'dt': [], 'ml': 0, 'na': 'apple', 'pos': -1, 'rel': '', 'st_var': '', 'tp':…
xin.chen
  • 964
  • 2
  • 8
  • 24
1
2 3
14 15