1.安装redis模块:pip install redis
2.安装好以后主要使用redis模块中的StrictRedis对象,用于连接redis服务器
3.代码如下:
from redis import StrictRedis redis_test=StrictRedis(host="127.0.0.1",port=6379) result=redis_test.set("name","python") print(result)
下面是不同数据类型对应的不同方法:
string
- set
- setex
- mset
- append
- get
- mget
- key
keys
- exists
- type
- delete
- expire
- getrange
- ttl
hash
- hset
- hmset
- hkeys
- hget
- hmget
- hvals
- hdel
list
- lpush
- rpush
- linsert
- lrange
- lset
- lrem
set
- sadd
- smembers
- srem
zset
- zadd
- zrange
- zrangebyscore
- zscore
- zrem
- zremrangebyscore