forked from p53841790/wheat-cache
feat(structure-channelx): add channelx
This commit is contained in:
parent
3f337dba9b
commit
c381c57374
|
@ -0,0 +1,59 @@
|
|||
package channelx
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"gitee.com/wheat-os/wheatCache/pkg/structure"
|
||||
)
|
||||
|
||||
type ChannelX struct {
|
||||
channel chan *structure.Value
|
||||
sizeByte int64
|
||||
}
|
||||
|
||||
func MakeChannelX(length int) *ChannelX {
|
||||
return &ChannelX{
|
||||
channel: make(chan *structure.Value, length),
|
||||
sizeByte: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ChannelX) SizeByte() int64 {
|
||||
return c.sizeByte
|
||||
}
|
||||
|
||||
// RollBack TODO 事务相关, V2 实现
|
||||
func (c *ChannelX) RollBack() error {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
// Begin 事务相关, V2 实现
|
||||
func (c *ChannelX) Begin() error {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
// Comment 事务相关, V2 实现
|
||||
func (c *ChannelX) Comment() error {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (c *ChannelX) Encode() ([]byte, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (c *ChannelX) Push(value string) structure.UpdateLength {
|
||||
val := structure.NewValue(value)
|
||||
up := val.GetSize()
|
||||
c.channel <- val
|
||||
atomic.AddInt64(&c.sizeByte, int64(up))
|
||||
return structure.UpdateLength(up)
|
||||
}
|
||||
|
||||
func (c *ChannelX) Pop() (string, structure.UpdateLength) {
|
||||
val := <-c.channel
|
||||
return val.ToString(), structure.UpdateLength(val.GetSize())
|
||||
}
|
||||
|
||||
func (c *ChannelX) Length() int {
|
||||
return len(c.channel)
|
||||
}
|
|
@ -67,3 +67,10 @@ type HashXInterface interface {
|
|||
Length() int
|
||||
Range(consur, count int, regex string) []string
|
||||
}
|
||||
|
||||
type ChannelXInterface interface {
|
||||
KeyBaseInterface
|
||||
Push(value string) UpdateLength
|
||||
Pop() (string, UpdateLength)
|
||||
Length() int
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"gitee.com/wheat-os/wheatCache/pkg/errorx"
|
||||
"gitee.com/wheat-os/wheatCache/pkg/proto"
|
||||
"gitee.com/wheat-os/wheatCache/pkg/structure"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func (d *Dao) CPush(key *proto.BaseKey, Value []string) (interface{}, error) {
|
||||
val, ok := d.lru.Get(key)
|
||||
if !ok {
|
||||
return nil, errorx.NotKeyErr(key.Key)
|
||||
}
|
||||
chanVal, ok := val.()
|
||||
}
|
||||
|
||||
func (d *Dao) CPop(_ *proto.BaseKey, _ int32) (interface{}, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) CMake(key *proto.BaseKey, length int32) (*proto.CMakeResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) CLen(_ *proto.BaseKey) (*proto.CLenResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) CClean(_ *proto.BaseKey) (*proto.CCleanResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
Loading…
Reference in New Issue