cursor

Redis开发规范

旧时模样 提交于 2020-01-24 15:29:13
Redis开发规范 参考: https://yq.aliyun.com/articles/531067 一、键值设计 1. key名设计 (1)【建议】: 可读性和可管理性 以业务名(或数据库名)为前缀(防止key冲突),用冒号分隔,比如业务名:表名:id ugc:video:1 (2)【建议】:简洁性 保证语义的前提下,控制key的长度,当key较多时,内存占用也不容忽视,例如: user:{uid}:friends:messages:{mid}简化为u:{uid}:fr:m:{mid}。 (3)【强制】:不要包含特殊字符 反例:包含空格、换行、单双引号以及其他转义字符 详细解析 2. value设计 (1)【强制】:拒绝bigkey(防止网卡流量、慢查询) string类型控制在10KB以内,hash、list、set、zset元素个数不要超过5000。 反例:一个包含200万个元素的list。 非字符串的bigkey,不要使用del删除,使用hscan、sscan、zscan方式渐进式删除,同时要注意防止bigkey过期时间自动删除问题(例如一个200万的zset设置1小时过期,会触发del操作,造成阻塞,而且该操作不会不出现在慢查询中(latency可查)), 查找方法 和 删除方法 详细解析 (2)【推荐】:选择适合的数据类型。 例如:实体类型

Cursors with postgres, where is the data stored and how many calls to the DB

╄→尐↘猪︶ㄣ 提交于 2020-01-24 05:00:06
问题 Hi I am using psycopg2 for postgres access. I am trying to understand where "cursor" stores the returned rows. Does it store it in the database as a temporary table or is it on the clients end? Does cursor (when you specify to fetch many rows) hit the database a query at a time or does it hit the database once ,get the first set of results then when you iterate over the returned values, it gets the next set (buffering). I have read multiple articles on cursor but nothing really gives the

Python中使用SQLite

时间秒杀一切 提交于 2020-01-24 03:06:13
使用SQLite SQLite是一种嵌入式数据库,它的数据库就是一个文件。由于SQLite本身是用C写的,而且体积很小,所以经常被集成到各种应用程序中,甚至在IOS和Android的APP中都可以集成。 Python中内置了SQLite3,连接到数据库后,需要打开游标Cursor,通过Cursor执行SQL语句,然后获得执行结果,Python定义了一套操作数据库的API接口,任何数据库要连接到Python,只需要提供符合Python标准的数据库驱动即可。试一下: ''' 遇到问题没人解答?小编创建了一个Python学习交流QQ群:579817333 寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书! ''' #导入SQLite驱动: import sqlite3 #连接到SQlite数据库 #数据库文件是test.db,不存在,则自动创建 conn = sqlite3 . connect ( 'test.db' ) #创建一个cursor: cursor = conn . cursor ( ) #执行一条SQL语句:创建user表 cursor . execute ( 'create table user(id varchar(20) primary key,name varchar(20))' ) #插入一条记录: cursor . execute (

startManagingCursor(cursor) deprecated method

断了今生、忘了曾经 提交于 2020-01-24 02:20:08
问题 I used this code: Cursor c = cr.query(message, null, null, null, null); startManagingCursor(c); But startManagingCursor(c) is a deprecated method. How can i replace it? 回答1: This method was deprecated in API level 11. Use the new CursorLoader class with LoaderManager instead; this is also available on older platforms through the Android compatibility package. Check out this tutorial series. 来源: https://stackoverflow.com/questions/27207989/startmanagingcursorcursor-deprecated-method

Linux command line shortcut

情到浓时终转凉″ 提交于 2020-01-24 00:58:33
It may or may not surprise you to know that the bash shell has a very rich array of convenient shortcuts that can make your life, working with the command line, a whole lot easier. This ability to edit the command line using shortcuts is provided by the GNU Readline library . This library is used by many other *nix application besides bash , so learning some of these shortcuts will not only allow you to zip around bash commands with absurd ease :), but can also make you more proficient in using a variety of other *nix applications that use Readline. I don’t want to get into Readline too deeply

【JUC】CopyOnWriteArrayList

倾然丶 夕夏残阳落幕 提交于 2020-01-23 21:10:54
写入时复制(CopyOnWrite) 什么是CopyOnWrite容器   CopyOnWrite容器即写时复制的容器。通俗的理解是当我们往一个容器添加元素的时候,不直接往当前容器添加,而是先将当前容器进行Copy,复制出一个新的容器,然后新的容器里添加元素,添加完元素之后,再将原容器的引用指向新的容器。 这样做的好处是我们可以对CopyOnWrite容器进行并发的读,而不需要加锁,因为写方法不会影响到读的容器。 所以CopyOnWrite容器也是一种 读写分离的思想,读和写不同的容器 。读不加锁,写要加。(写包含了add,remove,用ReentrantLock加锁) CopyOnWriteArrayList的实现原理   在使用CopyOnWriteArrayList之前,我们先阅读其源码了解下它是如何实现的。以下代码是向CopyOnWriteArrayList中add方法的实现(向CopyOnWriteArrayList里添加元素),可以发现在添加的时候是需要加锁的,否则多线程写的时候会Copy出N个副本出来。 类的内部类: COWIterator类  static final class COWIterator<E> implements ListIterator<E> { /** Snapshot of the array */ // 快照 private final

Mongodb cxx + Unreal Engine 4 - Crash while iterating over Cursor

淺唱寂寞╮ 提交于 2020-01-23 12:06:09
问题 I got an error while or after iterating over a mongocxx::cursor after finding some documents in my database. I am using Windows 10, Unreal Engine 4.16.1 and mongodb cxx 3.1.1. The database connection is set up correctly, the find function finds my documents and returns a valid cursor. It ends up in this Exception: Exception thrown at 0x00007FFDED56B698 (UE4Editor-Core.dll) in UE4Editor.exe: 0xC0000005: Access violation writing location 0x0000000000000010. with this output: 2598:0a50 @

Mongodb cxx + Unreal Engine 4 - Crash while iterating over Cursor

孤者浪人 提交于 2020-01-23 12:06:04
问题 I got an error while or after iterating over a mongocxx::cursor after finding some documents in my database. I am using Windows 10, Unreal Engine 4.16.1 and mongodb cxx 3.1.1. The database connection is set up correctly, the find function finds my documents and returns a valid cursor. It ends up in this Exception: Exception thrown at 0x00007FFDED56B698 (UE4Editor-Core.dll) in UE4Editor.exe: 0xC0000005: Access violation writing location 0x0000000000000010. with this output: 2598:0a50 @

Redis-Jedis使用Scan实现redis前缀key查找

北城以北 提交于 2020-01-23 10:53:18
  我们都知道Redis是单线程的,因此我们在使用一些命令(例如keys)的时候需要非常谨慎,可能一不小心就会阻塞进程,进而引起雪崩,这时候 scan命令就有了比较明显的优势; scan命令简介:   SCAN 命令(在Redis2.8版本引入)是一个基于游标的迭代器(cursor based iterator): SCAN 命令每次被调用之后, 都会向用户返回一个新的游标, 用户在下次迭代时需要使用这个新游标作为 SCAN 命令的游标参数, 以此来延续之前的迭代过程,当 SCAN 命令的游标参数被设置为 0 时, 服务器将开始一次新的迭代, 而当服务器向用户返回值为 0 的游标时, 表示迭代已结束。    命令格式如下: SCAN cursor [MATCH pattern] [COUNT count]   其中cursor为游标,MATCH和COUNT为可选参数; 迭代过程示例如下(查询以PLFX-ZZSFP-为前缀的key): 127.0.0.1:6379> scan 0 match PLFX-ZZSFP-* count 5 1) "1536" 2) (empty list or set) 127.0.0.1:6379> scan 1536 match PLFX-ZZSFP-* count 5 1) "1280" 2) (empty list or set) 127.0.0

Detect if cursor is hidden on Mac OS X

帅比萌擦擦* 提交于 2020-01-23 05:17:41
问题 Is there a programmatic, non-private-API way to detect whether the mouse cursor is hidden on Mac OS X? (As occurs, for example, when typing into a text field.) NSCursor has hide and unhide but no isHidden . I'm wondering if there is some other API which might do what I want. C-based APIs are fine. 回答1: Try CGCursorIsVisible() (returns a BOOL ). 来源: https://stackoverflow.com/questions/5026660/detect-if-cursor-is-hidden-on-mac-os-x