码迷,mamicode.com
首页 > 编程语言 > 详细

190707Python-Redis

时间:2019-07-07 12:48:56      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:sre   members   **kwargs   scan   gets   bit   dex   rpo   elf   

一、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

标签:sre   members   **kwargs   scan   gets   bit   dex   rpo   elf   

原文地址:https://www.cnblogs.com/L-dongf/p/11145714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!