190707Python-Redis

Posted l-dongf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了190707Python-Redis相关的知识,希望对你有一定的参考价值。

一、Redis的简单使用

  • Redis操作模式
# Author:Li Dongfei
import redis
r = redis.Redis(host='192.168.56.7', port=6379)
r.set('foo', 'bar')
print(r.get('foo'))
  • Redis连接池
# Author:Li Dongfei
import redis
pool = redis.ConnectionPool(host='192.168.56.7', port=6379)
r = redis.Redis(connection_pool=pool)
r.set('foo', 'bar')
print(r.get('foo'))

二、string

  • set(name, value, ex=None, px=None, nx=False, xx=False)
  • setnx(name, value)
  • setex(name, value, time)
  • psetex(name, time_ms, value)
  • mset(*args, **kwargs)
  • get(name)
  • mget(keys, *args)
  • getset(name, value)
  • getrange(key, start, end)
  • setrange(name, offset, value)
  • setbit(name, offset, value)
  • bitcount(key, start=None, end=None)
  • bitop(operation, dest, *keys)
  • strlen(name)
  • incr(self, name, amount=1)
  • incrbyfloat(self, name, amount=1.0)
  • decr(self, name, amount=1)
  • append(key, value)

三、hash

  • hset(name, key, value)
  • hmset(name, mapping)
  • hget(name,key)
  • hmget(name, keys, *args)
  • hgetall(name)
  • hlen(name)
  • hkeys(name)
  • hvals(name)
  • hexists(name, key)
  • hdel(name,*keys)
  • hincrby(name, key, amount=1)
  • hincrbyfloat(name, key, amount=1.0)
  • hscan(name, cursor=0, match=None, count=None)
  • hscan_iter(name, match=None, count=None)

四、list

  • lpush(name,values)
  • lpushx(name,value)
  • llen(name)
  • linsert(name, where, refvalue, value))
  • r.lset(name, index, value)
  • r.lrem(name, value, num)
  • lpop(name)
  • lindex(name, index)
  • lrange(name, start, end)
  • ltrim(name, start, end)
  • rpoplpush(src, dst)
  • blpop(keys, timeout)
  • brpoplpush(src, dst, timeout=0)

五、set

  • sadd(name,values)
  • scard(name)
  • sdiff(keys, *args)
  • sdiffstore(dest, keys, *args)
  • sinter(keys, *args)
  • sinterstore(dest, keys, *args)
  • sismember(name, value)
  • smembers(name)
  • smove(src, dst, value)
  • spop(name)
  • srandmember(name, numbers)
  • srem(name, values)
  • sunion(keys, *args)
  • sunionstore(dest,keys, *args)
  • sscan(name, cursor=0, match=None, count=None)
  • sscan_iter(name, match=None, count=None)

以上是关于190707Python-Redis的主要内容,如果未能解决你的问题,请参考以下文章

190707Python-Redis