redis 实现栈 - python

python实现栈

class FooStack(object):
    def __init__(self):
        self.items = []

    def push(self,item):
        self.items.append(item)

    def pop(self):
        return self.items.pop()

if __name__ == "__main__":
    val = FooStack()
    val.push(1)
    val.push(2)
    val.push(3)

    print(val.pop())
    print(val.pop())
    print(val.pop())

 

redis实现栈

import redis
conn = redis.Redis(host="10.0.0.200",port=6379,password="luffy1234")
class FooStack(object):
    def __init__(self,name):
        self.name = name
        self.conn = conn

    def push(self, item):
        self.conn.lpush(self.name,item)

    def pop(self):
        return self.conn.lpop(self.name)


if __name__ == "__main__":
    val = FooStack("name")
    val.push(1)
    val.push(2)
    val.push(3)

    print(val.pop())
    print(val.pop())
    print(val.pop())
posted @ 2018-07-27 11:56  Alice的小屋  阅读(1323)  评论(0编辑  收藏  举报