mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-27 09:48:09 -07:00
switch on event; scaffolding for redis driver
This commit is contained in:
+79
-23
@@ -139,45 +139,101 @@ func (ds *DS) Begin() (storage.Tx, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *Tx) Close() {
|
||||
if t.done {
|
||||
func (tx *Tx) close() {
|
||||
if tx.done {
|
||||
panic("redis: transaction closed twice")
|
||||
}
|
||||
t.done = true
|
||||
t.Conn.Close()
|
||||
tx.done = true
|
||||
tx.Conn.Close()
|
||||
}
|
||||
|
||||
func (t *Tx) UnpruneTorrent(torrent *storage.Torrent) error {
|
||||
if t.done {
|
||||
func (tx *Tx) Commit() error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
key := t.conf.Prefix + "Torrent:" + torrent.Infohash
|
||||
err := t.Send("HSET " + key + " Status 0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Tx) Commit() error {
|
||||
if t.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
_, err := t.Do("EXEC")
|
||||
_, err := tx.Do("EXEC")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.Close()
|
||||
tx.close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Redis doesn't need to rollback. Exec is atomic.
|
||||
func (t *Tx) Rollback() error {
|
||||
if t.done {
|
||||
func (tx *Tx) Rollback() error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
t.Close()
|
||||
tx.close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) Snatch(user *storage.User, torrent *storage.Torrent) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) Unprune(t *storage.Torrent) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
key := tx.conf.Prefix + "Torrent:" + t.Infohash
|
||||
err := tx.Send("HSET " + key + " Status 0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) NewLeecher(t *storage.Torrent, p *storage.Peer) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) RmLeecher(t *storage.Torrent, p *storage.Peer) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) NewSeeder(t *storage.Torrent, p *storage.Peer) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) RmSeeder(t *storage.Torrent, p *storage.Peer) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) IncrementSlots(u *storage.User) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) DecrementSlots(u *storage.User) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+8
-7
@@ -73,16 +73,17 @@ type Tx interface {
|
||||
Rollback() error
|
||||
|
||||
// Torrents
|
||||
Snatch(userID, torrentID uint64) error
|
||||
Unprune(torrentID uint64) error
|
||||
Snatch(u *User, t *Torrent) error
|
||||
Unprune(t *Torrent) error
|
||||
|
||||
// Peers
|
||||
NewLeecher(torrent *Torrent, p *Peer) error
|
||||
RmLeecher(torrentID uint64, peerID string) error
|
||||
NewLeecher(t *Torrent, p *Peer) error
|
||||
RmLeecher(t *Torrent, p *Peer) error
|
||||
|
||||
NewSeeder(torrent *Torrent, p *Peer) error
|
||||
RmSeeder(torrentID uint64, peerID string) error
|
||||
NewSeeder(t *Torrent, p *Peer) error
|
||||
RmSeeder(t *Torrent, p *Peer) error
|
||||
|
||||
// Users
|
||||
DecrementSlots(userID uint64) error
|
||||
IncrementSlots(u *User) error
|
||||
DecrementSlots(u *User) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user