$ pip install redis
python
import redis
redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
python
redis_client.set('key', 'value')
value = redis_client.get('key')
python
redis_client.lpush('list_key', 'item1', 'item2', 'item3')
items = redis_client.lrange('list_key', 0, -1)
python
redis_client.hmset('hash_key', {'field1': 'value1', 'field2': 'value2'})
values = redis_client.hgetall('hash_key')
python
redis_client.close()
python
import redis
redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
redis_client.set('key', 'value')
value = redis_client.get('key')
print(value)
redis_client.lpush('list_key', 'item1', 'item2', 'item3')
items = redis_client.lrange('list_key', 0, -1)
print(items)
redis_client.hmset('hash_key', {'field1': 'value1', 'field2': 'value2'})
values = redis_client.hgetall('hash_key')
print(values)
redis_client.close()
python
import redis
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
redis_client = redis.StrictRedis(connection_pool=pool)