Redis Sort

redis sort


CHAPTER 3

Commands in Redis

>>> conn.sort('sort-input', alpha=True)

And we can sort the

['110', '15', '23', '7']

items alphabetically.

>>> conn.hset('d-7', 'field', 5)

1L

>>> conn.hset('d-15', 'field', 1)

We are just adding some

1L

additional data for SORTing

>>> conn.hset('d-23', 'field', 9)

and fetching.

1L

>>> conn.hset('d-110', 'field', 3)

We can sort our

1L

data by fields of

>>> conn.sort('sort-input', by='d-*->field')

HASHes.

['15', '110', '7', '23']

>>> conn.sort('sort-input', by='d-*->field', get='d-*->field')

['1', '3', '5', '9']

And we can even fetch that data and return it

instead of or in addition to our input data.

Sorting can be used to sort LIST s, but it can also sort SETs, turning the result into a

LIST . In this example, we sorted numbers character by character (via the alpha key-

word argument), we sorted some items based on external data, and we were even able

to fetch external data to return. When combined with SET intersection, union, and

difference, along with storing data externally inside HASHes, SORT is a powerful com-

mand. We’ll spend some time talking about how to combine SET operations with SORT

in chapter 7.

Though SORT is the only command that can manipulate three types of data at the

same time, basic Redis transactions can let you manipulate multiple data types with a

series of commands without interruption

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 小男孩儿奶奶家的菜园子里有一个西红柿妖怪,她跟普通西红柿颜色不同,她是紫红色的,而且她会说话。 有一天小男孩儿去奶...
    吃苹果的猴子阅读 417评论 4 3
  • 从半年前的承马首马起,就酝酿了好多次,想开始记录自己的跑步以来的历程,都感觉还没到时候。在这样的纠结中迎来了4月,...
    Fortune_c409阅读 953评论 0 2
  • 梦境: 在五舅妈厨房位置玩,发现手机丢了,然后在床上找到了刘淳的手机,就让王小毛给刘淳打电话让她回来拿,顺...
    是魔王大人阅读 237评论 8 0
  • 近期由于一个项目的需要,我初步接触了exe程序反汇编。折腾了好几天终于见到了那个程序中急需的算法的真面目了。回顾整...
    fishmai0阅读 2,092评论 0 1
  • 没有了夏日的燥热, 秋天来了,心里清凉多了 站在浅秋,守一份安宁, 看云,云淡风轻 看湛蓝,宇天明净 看颜色越发好...
    娄娄姐阅读 225评论 0 0